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

Skip to content

Commit 4d2789c

Browse files
committed
Added tests for behavior when execution invalid objects or unit test code that is raising exceptions in different blocks.
Changed error message raised when suite is not found to be more adequate to the reasons for the error.
1 parent 26273ad commit 4d2789c

11 files changed

Lines changed: 410 additions & 1 deletion

source/core/ut_suite_manager.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ create or replace package body ut_suite_manager is
509509
l_suite := l_schema_suites(l_root_suite_name);
510510
exception
511511
when no_data_found then
512-
raise_application_error(-20203, 'Suite ' || l_root_suite_name || ' not found');
512+
raise_application_error(-20203, 'Suite ' || l_root_suite_name || ' does not exist or is invalid');
513513
end;
514514

515515
skip_by_path(l_suite, regexp_substr(l_suite_path, '\.(.+)', subexpression => 1));

tests/RunAll.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ create table ut$test_table (val varchar2(1));
124124
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPathCurUser.sql
125125
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPath.sql
126126
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPathCurUser.sql
127+
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.DoesntFindTheSuiteWhenPackageSpecIsInvalid.sql
127128

128129
@@lib/RunTest.sql ut_test/ut_test.IgnoreFlagSkipTest.sql
129130
@@lib/RunTest.sql ut_test/ut_test.OwnerNameInvalid.sql
@@ -145,7 +146,15 @@ create table ut$test_table (val varchar2(1));
145146
@@lib/RunTest.sql ut_test/ut_test.TeardownProcedureNameNull.sql
146147
@@lib/RunTest.sql ut_test/ut_test.IgnoreTollbackToSavepointException.sql
147148

149+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsATestWhenAfterTestFails.sql
150+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsATestWhenBeforeTestFails.sql
151+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenBeforeAllFails.sql
152+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenBeforeEachFails.sql
153+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenPackageHasInvalidBody.sql
154+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenPackageHasNoBody.sql
148155
@@lib/RunTest.sql ut_test_suite/ut_test_suite.IgnoreFlagSkipSuite.sql
156+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ReportsWarningsATestWhenAfterAllFails.sql
157+
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ReportsWarningsATestWhenAfterEachFails.sql
149158
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.Auto.sql
150159
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.AutoOnFailure.sql
151160
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.Manual.sql
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
set termout off
2+
create or replace package failing_invalid_spec as
3+
--%suite
4+
gv_glob_val non_existing_table.id%type := 0;
5+
6+
--%beforeall
7+
procedure before_all;
8+
--%test
9+
procedure test1;
10+
--%test
11+
procedure test2;
12+
end;
13+
/
14+
create or replace package body failing_invalid_spec as
15+
procedure before_all is begin gv_glob_val := 1; end;
16+
procedure test1 is begin ut.expect(1).to_equal(1); end;
17+
procedure test2 is begin ut.expect(1).to_equal(1); end;
18+
end;
19+
/
20+
set termout on
21+
22+
declare
23+
l_objects_to_run ut_suite_items;
24+
begin
25+
begin
26+
--act
27+
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list('failing_invalid_spec'));
28+
exception
29+
when others then
30+
if sqlerrm like '%failing_invalid_spec%' then
31+
:test_result := ut_utils.tr_success;
32+
end if;
33+
end;
34+
35+
if :test_result != ut_utils.tr_success or :test_result is null then
36+
dbms_output.put_line('Failed: Expected exception with text like ''%failing_invalid_spec%'' but got:'''||sqlerrm||'''');
37+
end if;
38+
end;
39+
/
40+
41+
drop package failing_invalid_spec
42+
/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
create or replace package failing_after_test as
2+
--%suite
3+
gv_glob_val number := 0;
4+
--%test
5+
--%aftertest(after_test1)
6+
procedure test1;
7+
procedure after_test1;
8+
--%test
9+
procedure test2;
10+
end;
11+
/
12+
create or replace package body failing_after_test as
13+
procedure test1 is begin gv_glob_val := 1; ut.expect(1).to_equal(2); end;
14+
procedure after_test1 is begin gv_glob_val := 1/0; end;
15+
procedure test2 is begin ut.expect(1).to_equal(1); end;
16+
end;
17+
/
18+
19+
declare
20+
l_output_data dbms_output.chararr;
21+
l_num_lines integer := 100000;
22+
begin
23+
--act
24+
ut.run('failing_after_test');
25+
dbms_output.get_lines( l_output_data, l_num_lines);
26+
if failing_after_test.gv_glob_val = 1 then
27+
for i in 1 .. l_num_lines loop
28+
if l_output_data(i) like '%2 tests, 0 failed, 1 errored%' then
29+
:test_result := ut_utils.tr_success;
30+
end if;
31+
end loop;
32+
if :test_result != ut_utils.tr_success or :test_result is null then
33+
for i in 1 .. l_num_lines loop
34+
dbms_output.put_line(l_output_data(i));
35+
end loop;
36+
dbms_output.put_line('Failed: test1 was not marked as failed');
37+
end if;
38+
else
39+
dbms_output.put_line('Failed: test1 was not executed');
40+
end if;
41+
42+
end;
43+
/
44+
45+
drop package failing_after_test
46+
/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
create or replace package failing_before_test as
2+
--%suite
3+
gv_glob_val number := 0;
4+
procedure before_test1;
5+
--%test
6+
--%beforetest(before_test1)
7+
procedure test1;
8+
--%test
9+
procedure test2;
10+
end;
11+
/
12+
create or replace package body failing_before_test as
13+
procedure before_test1 is begin gv_glob_val := 1/0; end;
14+
procedure test1 is begin gv_glob_val := 1; ut.expect(1).to_equal(2); end;
15+
procedure test2 is begin ut.expect(1).to_equal(1); end;
16+
end;
17+
/
18+
19+
declare
20+
l_output_data dbms_output.chararr;
21+
l_num_lines integer := 100000;
22+
begin
23+
--act
24+
ut.run('failing_before_test');
25+
dbms_output.get_lines( l_output_data, l_num_lines);
26+
if failing_before_test.gv_glob_val = 0 then
27+
for i in 1 .. l_num_lines loop
28+
if l_output_data(i) like '%2 tests, 0 failed, 1 errored%' then
29+
:test_result := ut_utils.tr_success;
30+
end if;
31+
end loop;
32+
if :test_result != ut_utils.tr_success or :test_result is null then
33+
for i in 1 .. l_num_lines loop
34+
dbms_output.put_line(l_output_data(i));
35+
end loop;
36+
dbms_output.put_line('Failed: test1 was not marked as failed');
37+
end if;
38+
else
39+
dbms_output.put_line('Failed: test1 was executed even though the beforetest failed');
40+
end if;
41+
42+
end;
43+
/
44+
45+
drop package failing_before_test
46+
/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
create or replace package failing_before_all as
2+
--%suite
3+
gv_glob_val number := 0;
4+
--%beforeall
5+
procedure before_all;
6+
--%test
7+
procedure test1;
8+
--%test
9+
procedure test2;
10+
end;
11+
/
12+
create or replace package body failing_before_all as
13+
procedure before_all is begin gv_glob_val := 1/0; end;
14+
procedure test1 is begin gv_glob_val := 1; ut.expect(1).to_equal(2); end;
15+
procedure test2 is begin gv_glob_val := 2; ut.expect(1).to_equal(2); end;
16+
end;
17+
/
18+
19+
declare
20+
l_output_data dbms_output.chararr;
21+
l_num_lines integer := 100000;
22+
begin
23+
--act
24+
ut.run('failing_before_all');
25+
26+
--assert
27+
if failing_before_all.gv_glob_val = 0 then
28+
dbms_output.get_lines( l_output_data, l_num_lines);
29+
for i in 1 .. l_num_lines loop
30+
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
31+
:test_result := ut_utils.tr_success;
32+
end if;
33+
end loop;
34+
if :test_result != ut_utils.tr_success or :test_result is null then
35+
for i in 1 .. l_num_lines loop
36+
dbms_output.put_line(l_output_data(i));
37+
end loop;
38+
dbms_output.put_line('Failed: Not all tests were marked as failed');
39+
end if;
40+
else
41+
dbms_output.put_line('Failed: tests were executed even though the beforeall failed');
42+
end if;
43+
end;
44+
/
45+
46+
drop package failing_before_all
47+
/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
create or replace package failing_before_each as
2+
--%suite
3+
gv_glob_val number := 0;
4+
--%beforeeach
5+
procedure before_each;
6+
--%test
7+
procedure test1;
8+
--%test
9+
procedure test2;
10+
end;
11+
/
12+
create or replace package body failing_before_each as
13+
procedure before_each is begin gv_glob_val := 1/0; end;
14+
procedure test1 is begin ut.expect(1).to_equal(2); end;
15+
procedure test2 is begin ut.expect(1).to_equal(2); end;
16+
end;
17+
/
18+
19+
declare
20+
l_output_data dbms_output.chararr;
21+
l_num_lines integer := 100000;
22+
begin
23+
--act
24+
ut.run('failing_before_each');
25+
26+
--assert
27+
if failing_before_each.gv_glob_val = 0 then
28+
dbms_output.get_lines( l_output_data, l_num_lines);
29+
for i in 1 .. l_num_lines loop
30+
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
31+
:test_result := ut_utils.tr_success;
32+
end if;
33+
end loop;
34+
35+
if :test_result != ut_utils.tr_success or :test_result is null then
36+
for i in 1 .. l_num_lines loop
37+
dbms_output.put_line(l_output_data(i));
38+
end loop;
39+
dbms_output.put_line('Failed: Not all tests were marked as failed');
40+
end if;
41+
else
42+
dbms_output.put_line('Failed: tests were executed even though the beforeall failed');
43+
end if;
44+
end;
45+
/
46+
47+
drop package failing_before_each
48+
/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
create or replace package failing_bad_body as
2+
--%suite
3+
gv_glob_val number := 0;
4+
--%beforeall
5+
procedure before_all;
6+
--%test
7+
procedure test1;
8+
--%test
9+
procedure test2;
10+
end;
11+
/
12+
set termout off
13+
create or replace package body failing_bad_body as
14+
begin
15+
null;
16+
end;
17+
/
18+
set termout on
19+
20+
declare
21+
l_output_data dbms_output.chararr;
22+
l_num_lines integer := 100000;
23+
begin
24+
--act
25+
ut.run('failing_bad_body');
26+
dbms_output.get_lines( l_output_data, l_num_lines);
27+
for i in 1 .. l_num_lines loop
28+
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
29+
:test_result := ut_utils.tr_success;
30+
end if;
31+
end loop;
32+
33+
if :test_result != ut_utils.tr_success or :test_result is null then
34+
for i in 1 .. l_num_lines loop
35+
dbms_output.put_line(l_output_data(i));
36+
end loop;
37+
dbms_output.put_line('Failed: Not all tests were marked as failed');
38+
end if;
39+
end;
40+
/
41+
42+
drop package failing_bad_body
43+
/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
create or replace package failing_no_body as
2+
--%suite
3+
gv_glob_val number := 0;
4+
--%beforeall
5+
procedure before_all;
6+
--%test
7+
procedure test1;
8+
--%test
9+
procedure test2;
10+
end;
11+
/
12+
13+
declare
14+
l_output_data dbms_output.chararr;
15+
l_num_lines integer := 100000;
16+
begin
17+
--act
18+
ut.run('failing_no_body');
19+
dbms_output.get_lines( l_output_data, l_num_lines);
20+
for i in 1 .. l_num_lines loop
21+
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
22+
:test_result := ut_utils.tr_success;
23+
end if;
24+
end loop;
25+
26+
if :test_result != ut_utils.tr_success or :test_result is null then
27+
for i in 1 .. l_num_lines loop
28+
dbms_output.put_line(l_output_data(i));
29+
end loop;
30+
dbms_output.put_line('Failed: Not all tests were marked as failed');
31+
end if;
32+
end;
33+
/
34+
35+
drop package failing_no_body
36+
/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
create or replace package failing_after_all as
2+
--%suite
3+
gv_glob_val number := 0;
4+
--%test
5+
procedure test1;
6+
--%test
7+
procedure test2;
8+
--%afterall
9+
procedure after_all;
10+
end;
11+
/
12+
create or replace package body failing_after_all as
13+
procedure test1 is begin gv_glob_val := gv_glob_val + 1; ut.expect(1).to_equal(2); end;
14+
procedure test2 is begin gv_glob_val := gv_glob_val + 1; ut.expect(1).to_equal(2); end;
15+
procedure after_all is begin gv_glob_val := 1/0; end;
16+
end;
17+
/
18+
19+
declare
20+
l_output_data dbms_output.chararr;
21+
l_num_lines integer := 100000;
22+
begin
23+
--act
24+
ut.run('failing_after_all');
25+
dbms_output.get_lines( l_output_data, l_num_lines);
26+
if failing_after_all.gv_glob_val = 2 then
27+
for i in 1 .. l_num_lines loop
28+
if l_output_data(i) like '%2 tests, 2 failed, 0 errored% 1 warning%' then
29+
:test_result := ut_utils.tr_success;
30+
end if;
31+
end loop;
32+
if :test_result != ut_utils.tr_success or :test_result is null then
33+
for i in 1 .. l_num_lines loop
34+
dbms_output.put_line(l_output_data(i));
35+
end loop;
36+
dbms_output.put_line('Failed: Not all tests were marked as failed');
37+
end if;
38+
else
39+
dbms_output.put_line('Failed: Not all tests were executed');
40+
end if;
41+
42+
end;
43+
/
44+
45+
drop package failing_after_all
46+
/

0 commit comments

Comments
 (0)