Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions docs/userguide/expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ To do that we use concept of expectation and a matcher to perform the check on t
Example of unit test procedure body with a single expectation.
```sql
begin
ut.expect( 'the tested value' ).to_equal('the expected value');
ut.expect( 'the tested value' ).to_( equal('the expected value') );
end;
```
Expand All @@ -19,6 +20,11 @@ Pseudo-code:
ut.expect( a_actual {data-type} ).not_to( {matcher} );
```

All matchers have shortcuts like:
```sql
ut.expect( a_actual {data-type} ).to_{matcher};
ut.expect( a_actual {data-type} ).not_to_{matcher};
```

# Matchers
utPLSQL provides following matchers to perform checks on the expected and actual values.
Expand All @@ -42,8 +48,11 @@ Validates that the actual value is between the lower and upper bound.
Example:
```sql
begin
ut.expect( a_actual => 3 ).to_be_between( a_lower_bound => 1, a_upper_bound => 3 );
ut.expect( 3 ).to_be_between( 1, 3 );
--or
ut.expect( a_actual => 3 ).to_( be_between( a_lower_bound => 1, a_upper_bound => 3 ) );
ut.expect( 3 ).to_( be_between( 1, 3 ) );
ut.expect( 3 ).to_( be_between( 1, 3 ) );
end;
```

Expand All @@ -56,6 +65,8 @@ procedure test_if_cursor_is_empty is
l_cursor sys_refcursor;
begin
open l_cursor for select * from dual where 1 = 0;
ut.expect( l_cursor ).to_be_empty();
--or
ut.expect( l_cursor ).to_( be_empty() );
end;
```
Expand All @@ -68,6 +79,8 @@ Unary matcher that validates if the provided value is false.
Usage:
```sql
begin
ut.expect( ( 1 = 0 ) ).to_be_false();
--or
ut.expect( ( 1 = 0 ) ).to_( be_false() );
end;
```
Expand All @@ -78,6 +91,8 @@ Allows to check if the actual value is greater or equal than the expected.
Usage:
```sql
begin
ut.expect( sysdate ).to_be_greater_or_equal( sysdate - 1 );
--or
ut.expect( sysdate ).to_( be_greater_or_equal( sysdate - 1 ) );
end;
```
Expand All @@ -88,6 +103,8 @@ Allows to check if the actual value is greater than the expected.
Usage:
```sql
begin
ut.expect( 2 ).to_be_greater_than( 1 );
--or
ut.expect( 2 ).to_( be_greater_than( 1 ) );
end;
```
Expand All @@ -98,6 +115,8 @@ Allows to check if the actual value is less or equal than the expected.
Usage:
```sql
begin
ut.expect( 3 ).to_be_less_or_equal( 3 );
--or
ut.expect( 3 ).to_( be_less_or_equal( 3 ) );
end;
```
Expand All @@ -108,6 +127,8 @@ Allows to check if the actual value is less than the expected.
Usage:
```sql
begin
ut.expect( 3 ).to_be_less_than( 2 );
--or
ut.expect( 3 ).to_( be_less_than( 2 ) );
end;
```
Expand All @@ -119,6 +140,9 @@ Validates that the actual value is like the expected expression.
Usage:
```sql
begin
ut.expect( 'Lorem_impsum' ).to_be_like( a_mask => '%rem\_%', a_escape_char => '\' );
ut.expect( 'Lorem_impsum' ).to_be_like( '%rem\_%', '\' );
--or
ut.expect( 'Lorem_impsum' ).to_( be_like( a_mask => '%rem\_%', a_escape_char => '\' ) );
ut.expect( 'Lorem_impsum' ).to_( be_like( '%rem\_%', '\' ) );
end;
Expand All @@ -133,7 +157,11 @@ Unary matcher that validates if the actual value is not null.
Usage:
```sql
begin
ut.expect( to_clob('ABC') ).to_be_not_null();
--or
ut.expect( to_clob('ABC') ).to_( be_not_null() );
--or
ut.expect( to_clob('ABC') ).not_to( be_null() );
end;
```

Expand All @@ -143,6 +171,8 @@ Unary matcher that validates if the actual value is null.
Usage:
```sql
begin
ut.expect( cast(null as varchar2(100)) ).to_be_null();
--or
ut.expect( cast(null as varchar2(100)) ).to_( be_null() );
end;
```
Expand All @@ -154,6 +184,8 @@ Unary matcher that validates if the provided value is false.
Usage:
```sql
begin
ut.expect( ( 1 = 1 ) ).to_be_true();
--or
ut.expect( ( 1 = 1 ) ).to_( be_true() );
end;
```
Expand All @@ -171,6 +203,9 @@ procedure check_if_cursors_are_equal is
x sys_refcursor;
y sys_refcursor;
begin
ut.expect( 'a dog' ).to_equal( 'a dog' );
ut.expect( a_actual => y ).to_equal( a_expected => x, a_nulls_are_equal => true );
--or
ut.expect( 'a dog' ).to_( equal( 'a dog' ) );
ut.expect( a_actual => y ).to_( equal( a_expected => x, a_nulls_are_equal => true ) );
end;
Expand All @@ -193,7 +228,7 @@ procedure test_cursors_skip_columns is
begin
open x for select 'text' ignore_me, d.* from user_tables d;
open y for select sysdate "ADate", d.* from user_tables d;
ut.expect( a_actual => y ).to_( equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' ) );
ut.expect( a_actual => y ).to_equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' );
end;
```

Expand Down Expand Up @@ -261,8 +296,8 @@ create or replace package body test_get_events is
l_actual := get_events(gc_event_date-1, gc_event_date+1);
ut.reset_nls();

ut.expect(l_actual).to_( equal(l_expected) );
ut.expect(l_actual).not_to( equal(l_expected_bad_date) );
ut.expect(l_actual).to_equal(l_expected);
ut.expect(l_actual).not_to_equal(l_expected_bad_date);
end;

end;
Expand Down Expand Up @@ -309,7 +344,7 @@ create or replace package body demo_dept as
begin
v_expected := department('HR');
v_actual := department('IT');
ut.expect( anydata.convertObject(v_expected) ).to_( equal( anydata.convertObject(v_actual) ) );
ut.expect( anydata.convertObject(v_expected) ).to_equal( anydata.convertObject(v_actual) );
end;

procedure test_department is
Expand All @@ -318,7 +353,7 @@ create or replace package body demo_dept as
begin
v_expected := departments(department('HR'));
v_actual := departments(department('IT'));
ut.expect( anydata.convertCollection(v_expected) ).to_( equal( anydata.convertCollection(v_actual) ) );
ut.expect( anydata.convertCollection(v_expected) ).to_equal( anydata.convertCollection(v_actual) );
end;

end;
Expand All @@ -333,6 +368,9 @@ Validates that the actual value is matching the expected regular expression.
Usage:
```sql
begin
ut.expect( a_actual => '123-456-ABcd' ).to_match( a_pattern => '\d{3}-\d{3}-[a-z]', a_modifiers => 'i' );
ut.expect( 'some value' ).to_match( '^some.*' );
--or
ut.expect( a_actual => '123-456-ABcd' ).to_( match( a_pattern => '\d{3}-\d{3}-[a-z]', a_modifiers => 'i' ) );
ut.expect( 'some value' ).to_( match( '^some.*' ) );
end;
Expand Down Expand Up @@ -370,13 +408,15 @@ Expectations provide a very convenient way to check for a negative of the expect
Syntax of check for matcher evaluating to true:
```sql
begin
ut.expect( a_actual {data-type} ).to_{matcher};
ut.expect( a_actual {data-type} ).to_( {matcher} );
end;
```

Syntax of check for matcher evaluating to false:
```sql
begin
begin
ut.expect( a_actual {data-type} ).not_to_{matcher};
ut.expect( a_actual {data-type} ).not_to( {matcher} );
end;
```
Expand Down
8 changes: 4 additions & 4 deletions examples/RunWithDocumentationReporter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ create or replace package body demo_doc_reporter1 is

procedure test_without_name is
begin
ut.expect(1).to_(equal(1));
ut.expect(1).to_equal(1);
end;

procedure failing_test is
begin
ut.expect(1).to_(equal(2));
ut.expect(1).to_equal(2);
end;
procedure failing_no_name is
begin
ut.expect(sysdate).to_(equal(to_char(sysdate)));
ut.expect(sysdate).to_equal(to_char(sysdate));
end;
procedure failing_exception_raised is
l_date date;
Expand Down Expand Up @@ -77,7 +77,7 @@ create or replace package body suite_package_without_name is

procedure passing_test2 is
begin
ut.expect(1).to_(equal(1));
ut.expect(1).to_equal(1);
end;
end;
/
Expand Down
8 changes: 4 additions & 4 deletions examples/award_bonus/test_award_bonus.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ create or replace package body test_award_bonus as
select salary as new_salary
from employees_test where employee_id = gc_test_employee;

ut.expect( results ).to_( equal( expected ) );
ut.expect( results ).to_equal( expected );

open results for
select * from employees_test where employee_id != gc_test_employee;

ut.expect( results ).to_( equal( not_affected ) );
ut.expect( results ).to_equal( not_affected );
end;

procedure fail_on_null_bonus is
begin
award_bonus(emp_id => gc_test_employee, sales_amt => null);
ut.expect( sqlcode ).not_to( equal( 0 ) );
ut.expect( sqlcode ).not_to_equal( 0 );
exception
when others then
ut.expect( sqlcode ).not_to( equal( 0 ) );
ut.expect( sqlcode ).not_to_equal( 0 );
end;

procedure add_employee( emp_id number, comm_pct number, sal number ) is
Expand Down
8 changes: 4 additions & 4 deletions examples/between_string/test_betwnstr.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ create or replace package body test_betwnstr as

procedure zero_start_position is
begin
ut.expect( betwnstr( '1234567', 0, 5 ) ).to_( equal('12345') );
ut.expect( betwnstr( '1234567', 0, 5 ) ).to_equal('12345');
end;

procedure big_end_position is
begin
ut.expect( betwnstr( '1234567', 0, 500 ) ).to_( equal('1234567') );
ut.expect( betwnstr( '1234567', 0, 500 ) ).to_equal('1234567');
end;

procedure null_string is
begin
ut.expect( betwnstr( null, 2, 5 ) ).to_( be_null );
ut.expect( betwnstr( null, 2, 5 ) ).to_be_null;
end;

procedure disabled_test is
begin
ut.expect( betwnstr( null, null, null) ).not_to( be_null );
ut.expect( betwnstr( null, null, null) ).not_to_be_null;
end;

end;
Expand Down
6 changes: 6 additions & 0 deletions examples/demo_expectations.pck
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ create or replace package body demo_expectations is
ut.expect(sysdate).not_to( be_between(sysdate+1,sysdate+2) );
ut.expect( 1 ).not_to( equal( 2 ) );
ut.expect( 'asd' ).not_to( be_like('z%q') );

ut.expect( sysdate ).not_to_be_null();
ut.expect( to_char(null) ).not_to_be_not_null();
ut.expect(sysdate).not_to_be_between(sysdate+1,sysdate+2);
ut.expect( 1 ).not_to_equal( 2 );
ut.expect( 'asd' ).not_to_be_like('z%q');
end;

end;
Expand Down
19 changes: 7 additions & 12 deletions examples/demo_of_expectations/demo_equal_matcher.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ create or replace package body demo_equal_matcher as
l_expected := demo_department('Sales');
--get the actual data
l_actual := demo_department('Sales');
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected)
);
end;

Expand All @@ -75,7 +75,7 @@ create or replace package body demo_equal_matcher as
l_expected := demo_department('Sales');
--get the actual data
-- nothing done
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected)
);
end;

Expand All @@ -84,24 +84,21 @@ create or replace package body demo_equal_matcher as
l_actual demo_department;
begin
l_actual := demo_department('Sales');
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
);
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
end;

procedure object_compare_null_both_ok is
l_expected demo_department;
l_actual demo_department;
begin
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
);
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
end;

procedure object_compare_null_both_fail is
l_expected demo_department;
l_actual demo_department;
begin
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected),false)
);
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected),false);
end;


Expand All @@ -113,8 +110,7 @@ create or replace package body demo_equal_matcher as
l_expected := demo_department('Sales');
--get the actual data
l_actual := demo_department('HR');
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
);
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
end;

procedure object_compare_different_type is
Expand All @@ -125,8 +121,7 @@ create or replace package body demo_equal_matcher as
l_expected := demo_department('Sales');
--get the actual data
l_actual := demo_department_new('Sales');
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
);
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
end;

end;
Expand Down
Loading