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

Skip to content

Commit ed5e2e2

Browse files
authored
Merge pull request #551 from AlexisGaldamez/new_design_expectations_test
New design for the expectations tests
2 parents 4a5fad4 + 002ae12 commit ed5e2e2

5 files changed

Lines changed: 142 additions & 59 deletions

File tree

test/core/expectations/test_expect_not_to_be_null.pkb

Lines changed: 81 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,198 @@
11
create or replace package body test_expect_not_to_be_null
22
is
3-
4-
procedure execute_expectation(a_data_type in varchar2,
5-
a_data_value in varchar2)
6-
is
7-
l_execute varchar2(32000);
8-
begin
9-
-- arrange
10-
l_execute := ' declare
11-
l_expected '||a_data_type||' := '||a_data_value||';
12-
begin
13-
--act - execute the expectation
14-
ut3.ut.expect(l_expected).not_to_be_null();
15-
end;';
16-
17-
execute immediate l_execute;
18-
end;
19-
20-
procedure test_success_expectacion(a_data_type in varchar2,
21-
a_data_value in varchar2)
3+
procedure cleanup_expectations
224
is
235
begin
24-
execute_expectation(a_data_type, a_data_value);
25-
26-
--assert - check that expectation was executed successfully
27-
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
28-
29-
-- cleanup
30-
ut3.ut_expectation_processor.clear_expectations();
31-
end;
32-
33-
procedure test_failure_expectacion(a_data_type in varchar2,
34-
a_data_value in varchar2)
35-
is
36-
begin
37-
execute_expectation(a_data_type, a_data_value);
38-
39-
--assert - check that expectation was a failure
40-
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_failure);
41-
42-
-- cleanup
436
ut3.ut_expectation_processor.clear_expectations();
447
end;
458

469
procedure blob_not_null
4710
is
4811
begin
49-
test_success_expectacion('blob', 'to_blob(''abc'')');
12+
--Act
13+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'blob', 'to_blob(''abc'')');
14+
--Assert
15+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
5016
end;
5117

5218
procedure blob_0_lengt
5319
is
5420
begin
55-
test_success_expectacion('blob', 'empty_blob()');
21+
--Act
22+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'blob', 'empty_blob()');
23+
--Assert
24+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
5625
end;
5726

5827
procedure boolean_not_null
5928
is
6029
begin
61-
test_success_expectacion('boolean', 'true');
30+
--Act
31+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'boolean', 'true');
32+
--Assert
33+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
6234
end;
6335

6436
procedure clob_not_null
6537
is
6638
begin
67-
test_success_expectacion('clob', 'to_clob(''abc'')');
39+
--Act
40+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'clob', 'to_clob(''abc'')');
41+
--Assert
42+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
6843
end;
6944

7045

7146
procedure clob_0_lengt
7247
is
7348
begin
74-
test_success_expectacion('clob', 'empty_clob()');
49+
--Act
50+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'clob', 'empty_clob()');
51+
--Assert
52+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
7553
end;
7654

7755
procedure date_not_null
7856
is
7957
begin
80-
test_success_expectacion('date', 'sysdate');
58+
--Act
59+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'date', 'sysdate');
60+
--Assert
61+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
8162
end;
8263

8364
procedure number_not_null
8465
is
8566
begin
86-
test_success_expectacion('number', '1234');
67+
--Act
68+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'number', '1234');
69+
--Assert
70+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
8771
end;
8872

8973
procedure timestamp_not_null
9074
is
9175
begin
92-
test_success_expectacion('timestamp', 'systimestamp');
76+
--Act
77+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'timestamp', 'systimestamp');
78+
--Assert
79+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
9380
end;
9481

9582
procedure timestamp_with_ltz_not_null
9683
is
9784
begin
98-
test_success_expectacion('timestamp with local time zone', 'systimestamp');
85+
--Act
86+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'timestamp with local time zone', 'systimestamp');
87+
--Assert
88+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
9989
end;
10090

10191
procedure timestamp_with_tz_not_null
10292
is
10393
begin
104-
test_success_expectacion('timestamp with time zone', 'systimestamp');
94+
--Act
95+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'timestamp with time zone', 'systimestamp');
96+
--Assert
97+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
10598
end;
10699

107100
procedure varchar2_not_null
108101
is
109102
begin
110-
test_success_expectacion('varchar2(4000)', '''abc''');
103+
--Act
104+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'varchar2(4000)', '''abc''');
105+
--Assert
106+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
111107
end;
112108

113109
procedure null_blob
114110
is
115111
begin
116-
test_failure_expectacion('blob', 'null');
112+
--Act
113+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'blob', 'null');
114+
--Assert
115+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
117116
end;
118117

119118

120119
procedure null_boolean
121120
is
122121
begin
123-
test_failure_expectacion('boolean', 'null');
122+
--Act
123+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'boolean', 'null');
124+
--Assert
125+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
124126
end;
125127

126128

127129
procedure null_clob
128130
is
129131
begin
130-
test_failure_expectacion('clob', 'null');
132+
--Act
133+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'clob', 'null');
134+
--Assert
135+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
131136
end;
132137

133138

134139
procedure null_date
135140
is
136141
begin
137-
test_failure_expectacion('date', 'null');
142+
--Act
143+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'date', 'null');
144+
--Assert
145+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
138146
end;
139147

140148

141149
procedure null_number
142150
is
143151
begin
144-
test_failure_expectacion('number', 'null');
152+
--Act
153+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'number', 'null');
154+
--Assert
155+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
145156
end;
146157

147158

148159
procedure null_timestamp
149160
is
150161
begin
151-
test_failure_expectacion('timestamp', 'null');
162+
--Act
163+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'timestamp', 'null');
164+
--Assert
165+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
152166
end;
153167

154168

155169
procedure null_timestamp_with_ltz
156170
is
157171
begin
158-
test_failure_expectacion('timestamp with local time zone', 'null');
172+
--Act
173+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'timestamp with local time zone', 'null');
174+
--Assert
175+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
159176
end;
160177

161178

162179
procedure null_timestamp_with_tz
163180
is
164181
begin
165-
test_failure_expectacion('timestamp with time zone', 'null');
182+
--Act
183+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'timestamp with time zone', 'null');
184+
--Assert
185+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
166186
end;
167187

168188

169189
procedure null_varchar2
170190
is
171191
begin
172-
test_failure_expectacion('varchar2(4000)', 'null');
192+
--Act
193+
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'varchar2(4000)', 'null');
194+
--Assert
195+
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).not_to_be_empty();
173196
end;
174197

175198
end test_expect_not_to_be_null;

test/core/expectations/test_expect_not_to_be_null.pks

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
create or replace package test_expect_not_to_be_null
22
is
33
--%suite(expectations - not_to_be_null)
4-
--%suitepath(utplsql.core.expectations.not_to_be_null)
4+
--%suitepath(utplsql.core.expectations.unary)
5+
6+
--%aftereach
7+
procedure cleanup_expectations;
58

69
--%test(Gives success for not null blob)
710
procedure blob_not_null;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
create or replace package body expectations_helpers
2+
is
3+
function unary_expectation_block(a_matcher_name in varchar2,
4+
a_data_type in varchar2,
5+
a_data_value in varchar2)
6+
return varchar2
7+
is
8+
l_execute varchar2(32000);
9+
begin
10+
l_execute := ' declare
11+
l_expected '||a_data_type||' := '||a_data_value||';
12+
begin
13+
--act - execute the expectation
14+
ut3.ut.expect(l_expected).'||a_matcher_name||'();
15+
end;';
16+
17+
return l_execute;
18+
end;
19+
20+
function binary_expectation_block(a_matcher_name in varchar2,
21+
a_data_type_1 in varchar2,
22+
a_data_value_1 in varchar2,
23+
a_data_type_2 in varchar2,
24+
a_data_value_2 in varchar2)
25+
return varchar2
26+
is
27+
l_execute varchar2(32000);
28+
begin
29+
l_execute := ' declare
30+
l_expected_1 '||a_data_type_1||' := '||a_data_value_1||';
31+
l_expected_2 '||a_data_type_2||' := '||a_data_value_2||';
32+
begin
33+
--act - execute the expectation
34+
ut3.ut.expect(l_expected_1).'||a_matcher_name||'(l_expected_2);
35+
end;';
36+
37+
return l_execute;
38+
end;
39+
end expectations_helpers;
40+
/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
create or replace package expectations_helpers
2+
is
3+
function unary_expectation_block(a_matcher_name in varchar2,
4+
a_data_type in varchar2,
5+
a_data_value in varchar2)
6+
return varchar2;
7+
8+
function binary_expectation_block(a_matcher_name in varchar2,
9+
a_data_type_1 in varchar2,
10+
a_data_value_1 in varchar2,
11+
a_data_type_2 in varchar2,
12+
a_data_value_2 in varchar2)
13+
return varchar2;
14+
end expectations_helpers;
15+
/

test/install_tests.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ whenever oserror exit failure rollback
99
@@helpers/ut_without_body.pks
1010
@@helpers/ut_with_invalid_body.pks
1111
@@helpers/ut_with_invalid_body.pkb
12+
@@helpers/expectations_helpers.pks
13+
@@helpers/expectations_helpers.pkb
1214

1315
--Install tests
1416
@@core.pks

0 commit comments

Comments
 (0)