@@ -6,6 +6,7 @@ To do that we use concept of expectation and a matcher to perform the check on t
66Example of unit test procedure body with a single expectation.
77``` sql
88begin
9+ ut .expect ( ' the tested value' ).to_equal(' the expected value' );
910 ut .expect ( ' the tested value' ).to_( equal(' the expected value' ) );
1011end;
1112```
@@ -19,6 +20,11 @@ Pseudo-code:
1920 ut .expect ( a_actual {data- type} ).not_to( {matcher} );
2021```
2122
23+ All matchers have shortcuts like:
24+ ``` sql
25+ ut .expect ( a_actual {data- type} ).to_{matcher};
26+ ut .expect ( a_actual {data- type} ).not_to_{matcher};
27+ ```
2228
2329# Matchers
2430utPLSQL provides following matchers to perform checks on the expected and actual values.
@@ -42,8 +48,11 @@ Validates that the actual value is between the lower and upper bound.
4248Example:
4349``` sql
4450begin
51+ ut .expect ( a_actual => 3 ).to_be_between( a_lower_bound => 1 , a_upper_bound => 3 );
52+ ut .expect ( 3 ).to_be_between( 1 , 3 );
53+ -- or
4554 ut .expect ( a_actual => 3 ).to_( be_between( a_lower_bound => 1 , a_upper_bound => 3 ) );
46- ut .expect ( 3 ).to_( be_between( 1 , 3 ) );
55+ ut .expect ( 3 ).to_( be_between( 1 , 3 ) );
4756end;
4857```
4958
@@ -56,6 +65,8 @@ procedure test_if_cursor_is_empty is
5665 l_cursor sys_refcursor;
5766begin
5867 open l_cursor for select * from dual where 1 = 0 ;
68+ ut .expect ( l_cursor ).to_be_empty();
69+ -- or
5970 ut .expect ( l_cursor ).to_( be_empty() );
6071end;
6172```
@@ -68,6 +79,8 @@ Unary matcher that validates if the provided value is false.
6879Usage:
6980``` sql
7081begin
82+ ut .expect ( ( 1 = 0 ) ).to_be_false();
83+ -- or
7184 ut .expect ( ( 1 = 0 ) ).to_( be_false() );
7285end;
7386```
@@ -78,6 +91,8 @@ Allows to check if the actual value is greater or equal than the expected.
7891Usage:
7992``` sql
8093begin
94+ ut .expect ( sysdate ).to_be_greater_or_equal( sysdate - 1 );
95+ -- or
8196 ut .expect ( sysdate ).to_( be_greater_or_equal( sysdate - 1 ) );
8297end;
8398```
@@ -88,6 +103,8 @@ Allows to check if the actual value is greater than the expected.
88103Usage:
89104``` sql
90105begin
106+ ut .expect ( 2 ).to_be_greater_than( 1 );
107+ -- or
91108 ut .expect ( 2 ).to_( be_greater_than( 1 ) );
92109end;
93110```
@@ -98,6 +115,8 @@ Allows to check if the actual value is less or equal than the expected.
98115Usage:
99116``` sql
100117begin
118+ ut .expect ( 3 ).to_be_less_or_equal( 3 );
119+ -- or
101120 ut .expect ( 3 ).to_( be_less_or_equal( 3 ) );
102121end;
103122```
@@ -108,6 +127,8 @@ Allows to check if the actual value is less than the expected.
108127Usage:
109128``` sql
110129begin
130+ ut .expect ( 3 ).to_be_less_than( 2 );
131+ -- or
111132 ut .expect ( 3 ).to_( be_less_than( 2 ) );
112133end;
113134```
@@ -119,6 +140,9 @@ Validates that the actual value is like the expected expression.
119140Usage:
120141``` sql
121142begin
143+ ut .expect ( ' Lorem_impsum' ).to_be_like( a_mask => ' %rem\_ %' , a_escape_char => ' \' );
144+ ut.expect( ' Lorem_impsum' ).to_be_like( ' %rem\_%' , ' \' );
145+ --or
122146 ut.expect( ' Lorem_impsum' ).to_( be_like( a_mask => ' %rem\_%' , a_escape_char => ' \' ) );
123147 ut.expect( ' Lorem_impsum' ).to_( be_like( ' %rem\_%' , ' \' ) );
124148end;
@@ -133,7 +157,11 @@ Unary matcher that validates if the actual value is not null.
133157Usage:
134158```sql
135159begin
160+ ut.expect( to_clob(' ABC' ) ).to_be_not_null();
161+ --or
136162 ut.expect( to_clob(' ABC' ) ).to_( be_not_null() );
163+ --or
164+ ut.expect( to_clob(' ABC' ) ).not_to( be_null() );
137165end;
138166```
139167
@@ -143,6 +171,8 @@ Unary matcher that validates if the actual value is null.
143171Usage:
144172```sql
145173begin
174+ ut.expect( cast(null as varchar2(100)) ).to_be_null();
175+ --or
146176 ut.expect( cast(null as varchar2(100)) ).to_( be_null() );
147177end;
148178```
@@ -154,6 +184,8 @@ Unary matcher that validates if the provided value is false.
154184Usage:
155185```sql
156186begin
187+ ut.expect( ( 1 = 1 ) ).to_be_true();
188+ --or
157189 ut.expect( ( 1 = 1 ) ).to_( be_true() );
158190end;
159191```
@@ -171,6 +203,9 @@ procedure check_if_cursors_are_equal is
171203 x sys_refcursor;
172204 y sys_refcursor;
173205begin
206+ ut.expect( ' a dog' ).to_equal( ' a dog' );
207+ ut.expect( a_actual => y ).to_equal( a_expected => x, a_nulls_are_equal => true );
208+ --or
174209 ut.expect( ' a dog' ).to_( equal( ' a dog' ) );
175210 ut.expect( a_actual => y ).to_( equal( a_expected => x, a_nulls_are_equal => true ) );
176211end;
@@ -193,7 +228,7 @@ procedure test_cursors_skip_columns is
193228begin
194229 open x for select 'text' ignore_me, d.* from user_tables d;
195230 open y for select sysdate "ADate", d.* from user_tables d;
196- ut.expect( a_actual => y ).to_( equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' ) );
231+ ut.expect( a_actual => y ).to_equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' );
197232end;
198233` ` `
199234
@@ -261,8 +296,8 @@ create or replace package body test_get_events is
261296 l_actual := get_events(gc_event_date-1, gc_event_date+1);
262297 ut.reset_nls();
263298
264- ut.expect(l_actual).to_( equal( l_expected) );
265- ut.expect(l_actual).not_to( equal( l_expected_bad_date) );
299+ ut.expect(l_actual).to_equal( l_expected);
300+ ut.expect(l_actual).not_to_equal( l_expected_bad_date);
266301 end;
267302
268303end;
@@ -309,7 +344,7 @@ create or replace package body demo_dept as
309344 begin
310345 v_expected := department('HR');
311346 v_actual := department('IT');
312- ut.expect( anydata.convertObject(v_expected) ).to_( equal( anydata.convertObject(v_actual) ) );
347+ ut.expect( anydata.convertObject(v_expected) ).to_equal( anydata.convertObject(v_actual) );
313348 end;
314349
315350 procedure test_department is
@@ -318,7 +353,7 @@ create or replace package body demo_dept as
318353 begin
319354 v_expected := departments(department('HR'));
320355 v_actual := departments(department('IT'));
321- ut.expect( anydata.convertCollection(v_expected) ).to_( equal( anydata.convertCollection(v_actual) ) );
356+ ut.expect( anydata.convertCollection(v_expected) ).to_equal( anydata.convertCollection(v_actual) );
322357 end;
323358
324359end;
@@ -333,6 +368,9 @@ Validates that the actual value is matching the expected regular expression.
333368Usage:
334369` ` ` sql
335370begin
371+ ut.expect( a_actual => '123-456-ABcd' ).to_match( a_pattern => '\d {3}-\d {3}-[a-z]', a_modifiers => 'i' );
372+ ut.expect( 'some value' ).to_match( '^some.*' );
373+ --or
336374 ut.expect( a_actual => '123-456-ABcd' ).to_( match( a_pattern => '\d {3}-\d {3}-[a-z]', a_modifiers => 'i' ) );
337375 ut.expect( 'some value' ).to_( match( '^some.*' ) );
338376end;
@@ -370,13 +408,15 @@ Expectations provide a very convenient way to check for a negative of the expect
370408Syntax of check for matcher evaluating to true:
371409` ` ` sql
372410begin
411+ ut.expect( a_actual {data-type} ).to_{matcher};
373412 ut.expect( a_actual {data-type} ).to_( {matcher} );
374413end;
375414` ` `
376415
377416Syntax of check for matcher evaluating to false:
378417` ` ` sql
379- begin
418+ begin
419+ ut.expect( a_actual {data-type} ).not_to_{matcher};
380420 ut.expect( a_actual {data-type} ).not_to( {matcher} );
381421end;
382422` ` `
0 commit comments