Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
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.
  • Loading branch information
jgebal committed Feb 23, 2017
commit 4d2789ce53935a243e459843d3730f6c9dcae9c9
2 changes: 1 addition & 1 deletion source/core/ut_suite_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ create or replace package body ut_suite_manager is
l_suite := l_schema_suites(l_root_suite_name);
exception
when no_data_found then
raise_application_error(-20203, 'Suite ' || l_root_suite_name || ' not found');
raise_application_error(-20203, 'Suite ' || l_root_suite_name || ' does not exist or is invalid');
end;

skip_by_path(l_suite, regexp_substr(l_suite_path, '\.(.+)', subexpression => 1));
Expand Down
9 changes: 9 additions & 0 deletions tests/RunAll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ create table ut$test_table (val varchar2(1));
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPathCurUser.sql
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPath.sql
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTop2PackageProcedureByPathCurUser.sql
@@lib/RunTest.sql ut_suite_manager/ut_suite_manager.DoesntFindTheSuiteWhenPackageSpecIsInvalid.sql

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

@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsATestWhenAfterTestFails.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsATestWhenBeforeTestFails.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenBeforeAllFails.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenBeforeEachFails.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenPackageHasInvalidBody.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsEachTestWhenPackageHasNoBody.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.IgnoreFlagSkipSuite.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ReportsWarningsATestWhenAfterAllFails.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ReportsWarningsATestWhenAfterEachFails.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.Auto.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.AutoOnFailure.sql
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.Manual.sql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
set termout off
create or replace package failing_invalid_spec as
--%suite
gv_glob_val non_existing_table.id%type := 0;

--%beforeall
procedure before_all;
--%test
procedure test1;
--%test
procedure test2;
end;
/
create or replace package body failing_invalid_spec as
procedure before_all is begin gv_glob_val := 1; end;
procedure test1 is begin ut.expect(1).to_equal(1); end;
procedure test2 is begin ut.expect(1).to_equal(1); end;
end;
/
set termout on

declare
l_objects_to_run ut_suite_items;
begin
begin
--act
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list('failing_invalid_spec'));
exception
when others then
if sqlerrm like '%failing_invalid_spec%' then
:test_result := ut_utils.tr_success;
end if;
end;

if :test_result != ut_utils.tr_success or :test_result is null then
dbms_output.put_line('Failed: Expected exception with text like ''%failing_invalid_spec%'' but got:'''||sqlerrm||'''');
end if;
end;
/

drop package failing_invalid_spec
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
create or replace package failing_after_test as
--%suite
gv_glob_val number := 0;
--%test
--%aftertest(after_test1)
procedure test1;
procedure after_test1;
--%test
procedure test2;
end;
/
create or replace package body failing_after_test as
procedure test1 is begin gv_glob_val := 1; ut.expect(1).to_equal(2); end;
procedure after_test1 is begin gv_glob_val := 1/0; end;
procedure test2 is begin ut.expect(1).to_equal(1); end;
end;
/

declare
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--act
ut.run('failing_after_test');
dbms_output.get_lines( l_output_data, l_num_lines);
if failing_after_test.gv_glob_val = 1 then
for i in 1 .. l_num_lines loop
if l_output_data(i) like '%2 tests, 0 failed, 1 errored%' then
:test_result := ut_utils.tr_success;
end if;
end loop;
if :test_result != ut_utils.tr_success or :test_result is null then
for i in 1 .. l_num_lines loop
dbms_output.put_line(l_output_data(i));
end loop;
dbms_output.put_line('Failed: test1 was not marked as failed');
end if;
else
dbms_output.put_line('Failed: test1 was not executed');
end if;

end;
/

drop package failing_after_test
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
create or replace package failing_before_test as
--%suite
gv_glob_val number := 0;
procedure before_test1;
--%test
--%beforetest(before_test1)
procedure test1;
--%test
procedure test2;
end;
/
create or replace package body failing_before_test as
procedure before_test1 is begin gv_glob_val := 1/0; end;
procedure test1 is begin gv_glob_val := 1; ut.expect(1).to_equal(2); end;
procedure test2 is begin ut.expect(1).to_equal(1); end;
end;
/

declare
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--act
ut.run('failing_before_test');
dbms_output.get_lines( l_output_data, l_num_lines);
if failing_before_test.gv_glob_val = 0 then
for i in 1 .. l_num_lines loop
if l_output_data(i) like '%2 tests, 0 failed, 1 errored%' then
:test_result := ut_utils.tr_success;
end if;
end loop;
if :test_result != ut_utils.tr_success or :test_result is null then
for i in 1 .. l_num_lines loop
dbms_output.put_line(l_output_data(i));
end loop;
dbms_output.put_line('Failed: test1 was not marked as failed');
end if;
else
dbms_output.put_line('Failed: test1 was executed even though the beforetest failed');
end if;

end;
/

drop package failing_before_test
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
create or replace package failing_before_all as
--%suite
gv_glob_val number := 0;
--%beforeall
procedure before_all;
--%test
procedure test1;
--%test
procedure test2;
end;
/
create or replace package body failing_before_all as
procedure before_all is begin gv_glob_val := 1/0; end;
procedure test1 is begin gv_glob_val := 1; ut.expect(1).to_equal(2); end;
procedure test2 is begin gv_glob_val := 2; ut.expect(1).to_equal(2); end;
end;
/

declare
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--act
ut.run('failing_before_all');

--assert
if failing_before_all.gv_glob_val = 0 then
dbms_output.get_lines( l_output_data, l_num_lines);
for i in 1 .. l_num_lines loop
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
:test_result := ut_utils.tr_success;
end if;
end loop;
if :test_result != ut_utils.tr_success or :test_result is null then
for i in 1 .. l_num_lines loop
dbms_output.put_line(l_output_data(i));
end loop;
dbms_output.put_line('Failed: Not all tests were marked as failed');
end if;
else
dbms_output.put_line('Failed: tests were executed even though the beforeall failed');
end if;
end;
/

drop package failing_before_all
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
create or replace package failing_before_each as
--%suite
gv_glob_val number := 0;
--%beforeeach
procedure before_each;
--%test
procedure test1;
--%test
procedure test2;
end;
/
create or replace package body failing_before_each as
procedure before_each is begin gv_glob_val := 1/0; end;
procedure test1 is begin ut.expect(1).to_equal(2); end;
procedure test2 is begin ut.expect(1).to_equal(2); end;
end;
/

declare
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--act
ut.run('failing_before_each');

--assert
if failing_before_each.gv_glob_val = 0 then
dbms_output.get_lines( l_output_data, l_num_lines);
for i in 1 .. l_num_lines loop
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
:test_result := ut_utils.tr_success;
end if;
end loop;

if :test_result != ut_utils.tr_success or :test_result is null then
for i in 1 .. l_num_lines loop
dbms_output.put_line(l_output_data(i));
end loop;
dbms_output.put_line('Failed: Not all tests were marked as failed');
end if;
else
dbms_output.put_line('Failed: tests were executed even though the beforeall failed');
end if;
end;
/

drop package failing_before_each
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
create or replace package failing_bad_body as
--%suite
gv_glob_val number := 0;
--%beforeall
procedure before_all;
--%test
procedure test1;
--%test
procedure test2;
end;
/
set termout off
create or replace package body failing_bad_body as
begin
null;
end;
/
set termout on

declare
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--act
ut.run('failing_bad_body');
dbms_output.get_lines( l_output_data, l_num_lines);
for i in 1 .. l_num_lines loop
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
:test_result := ut_utils.tr_success;
end if;
end loop;

if :test_result != ut_utils.tr_success or :test_result is null then
for i in 1 .. l_num_lines loop
dbms_output.put_line(l_output_data(i));
end loop;
dbms_output.put_line('Failed: Not all tests were marked as failed');
end if;
end;
/

drop package failing_bad_body
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
create or replace package failing_no_body as
--%suite
gv_glob_val number := 0;
--%beforeall
procedure before_all;
--%test
procedure test1;
--%test
procedure test2;
end;
/

declare
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--act
ut.run('failing_no_body');
dbms_output.get_lines( l_output_data, l_num_lines);
for i in 1 .. l_num_lines loop
if l_output_data(i) like '%2 tests, 0 failed, 2 errored%' then
:test_result := ut_utils.tr_success;
end if;
end loop;

if :test_result != ut_utils.tr_success or :test_result is null then
for i in 1 .. l_num_lines loop
dbms_output.put_line(l_output_data(i));
end loop;
dbms_output.put_line('Failed: Not all tests were marked as failed');
end if;
end;
/

drop package failing_no_body
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
create or replace package failing_after_all as
--%suite
gv_glob_val number := 0;
--%test
procedure test1;
--%test
procedure test2;
--%afterall
procedure after_all;
end;
/
create or replace package body failing_after_all as
procedure test1 is begin gv_glob_val := gv_glob_val + 1; ut.expect(1).to_equal(2); end;
procedure test2 is begin gv_glob_val := gv_glob_val + 1; ut.expect(1).to_equal(2); end;
procedure after_all is begin gv_glob_val := 1/0; end;
end;
/

declare
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--act
ut.run('failing_after_all');
dbms_output.get_lines( l_output_data, l_num_lines);
if failing_after_all.gv_glob_val = 2 then
for i in 1 .. l_num_lines loop
if l_output_data(i) like '%2 tests, 2 failed, 0 errored% 1 warning%' then
:test_result := ut_utils.tr_success;
end if;
end loop;
if :test_result != ut_utils.tr_success or :test_result is null then
for i in 1 .. l_num_lines loop
dbms_output.put_line(l_output_data(i));
end loop;
dbms_output.put_line('Failed: Not all tests were marked as failed');
end if;
else
dbms_output.put_line('Failed: Not all tests were executed');
end if;

end;
/

drop package failing_after_all
/
Loading