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

Skip to content

Commit 5ee8641

Browse files
committed
Added tests for ut.run procedure
1 parent a42e244 commit 5ee8641

4 files changed

Lines changed: 102 additions & 11 deletions

File tree

source/core/ut_suite_manager.pkb

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ create or replace package body ut_suite_manager is
1717
*/
1818

1919
gc_suitpath_error_message constant varchar2(100) := 'Suitepath exceeds 1000 CHAR on: ';
20+
gc_tag_errmsg constant number := 450;
2021

2122
type t_path_item is record (
2223
object_name varchar2(250),
@@ -691,6 +692,34 @@ create or replace package body ut_suite_manager is
691692
return l_suites;
692693
end;
693694

695+
function build_no_test_error_msg(
696+
a_schema_name in varchar2,
697+
a_suite_path in varchar2,
698+
a_procedure_name in varchar2,
699+
a_object_name in varchar2,
700+
a_tags in varchar2
701+
) return varchar2 is
702+
l_error_msg varchar2(500);
703+
begin
704+
if a_suite_path is not null then
705+
l_error_msg := 'No suite packages found for path '||a_schema_name||':'||a_suite_path;
706+
elsif a_procedure_name is not null then
707+
l_error_msg := 'Suite test '||a_schema_name||'.'||a_object_name|| '.'||a_procedure_name||' does not exist';
708+
elsif a_object_name is not null then
709+
l_error_msg := 'Suite package '||a_schema_name||'.'||a_object_name|| ' does not exist';
710+
end if;
711+
712+
if l_error_msg is null and a_tags is not null then
713+
l_error_msg := 'No tests found for tags: '||ut_utils.to_string(a_tags,a_max_output_len => gc_tag_errmsg);
714+
elsif l_error_msg is not null and a_tags is not null then
715+
l_error_msg := l_error_msg||'with tags: '||ut_utils.to_string(a_tags,a_max_output_len => gc_tag_errmsg);
716+
end if;
717+
718+
l_error_msg := l_error_msg ||'.';
719+
720+
return l_error_msg;
721+
end;
722+
694723
procedure configure_execution_by_path(
695724
a_paths in ut_varchar2_list,
696725
a_suites out nocopy ut_suite_items,
@@ -730,15 +759,9 @@ create or replace package body ut_suite_manager is
730759
a_tags
731760
);
732761
if a_suites.count = l_suites_count then
733-
if l_path_item.suite_path is not null then
734-
raise_application_error(ut_utils.gc_suite_package_not_found,'No suite packages found for path '||l_schema||':'||l_path_item.suite_path|| '.');
735-
elsif l_path_item.procedure_name is not null then
736-
raise_application_error(ut_utils.gc_suite_package_not_found,'Suite test '||l_schema||'.'||l_path_item.object_name|| '.'||l_path_item.procedure_name||' does not exist');
737-
elsif l_path_item.object_name is not null then
738-
raise_application_error(ut_utils.gc_suite_package_not_found,'Suite package '||l_schema||'.'||l_path_item.object_name|| ' does not exist');
739-
elsif a_tags is not null then
740-
raise_application_error(ut_utils.gc_suite_package_not_found,'No suite packages found for tags: '||ut_utils.to_string(a_tags,a_max_output_len => 450));
741-
end if;
762+
raise_application_error(ut_utils.gc_suite_package_not_found,build_no_test_error_msg(
763+
l_schema,l_path_item.suite_path,l_path_item.procedure_name,
764+
l_path_item.object_name,a_tags));
742765
end if;
743766
l_index := a_suites.first;
744767
l_suites_count := a_suites.count;

test/ut3_tester_helper/run_helper.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ create or replace package body run_helper is
206206
procedure test1;
207207

208208
--%test(Test2 from test package 1)
209-
--%tags(test1,suite1test1)
209+
--%tags(test1,suite1test2)
210210
procedure test2;
211211

212212
end test_package_1;

test/ut3_user/api/test_ut_run.pkb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,62 @@ Failures:%
895895
ut.expect( l_results ).to_be_like( '%test_package_2%' );
896896
ut.expect( l_results ).not_to_be_like( '%test_package_3%' );
897897
end;
898+
899+
procedure run_proc_pkg_name_no_tag is
900+
l_results clob;
901+
l_exp_message varchar2(4000);
902+
begin
903+
l_exp_message :=q'[ORA-20204: Suite package ut3_tester_helper.test_package_1 does not existwith tags: 'nonexists'.]';
904+
ut3.ut.run('ut3_tester_helper.test_package_1',a_tags => 'nonexists');
905+
l_results := ut3_tester_helper.main_helper.get_dbms_output_as_clob();
906+
ut.fail('Expecte test to fail');
907+
exception
908+
when others then
909+
ut.expect( sqlerrm ).to_be_like( l_exp_message );
910+
end;
911+
912+
procedure run_proc_pkg_name_tag is
913+
l_results clob;
914+
begin
915+
ut3.ut.run('ut3_tester_helper.test_package_1',a_tags => 'suite1test1');
916+
l_results := ut3_tester_helper.main_helper.get_dbms_output_as_clob();
917+
--Assert
918+
ut.expect( l_results ).to_be_like( '%test_package_1%' );
919+
ut.expect( l_results ).to_be_like( '%test_package_1.test1%executed%' );
920+
ut.expect( l_results ).not_to_be_like( '%test_package_1.test2%' );
921+
ut.expect( l_results ).not_to_be_like( '%test_package_2%' );
922+
ut.expect( l_results ).not_to_be_like( '%test_package_3%' );
923+
end;
924+
925+
procedure run_pkg_name_file_list_tag is
926+
l_results clob;
927+
begin
928+
ut3.ut.run('ut3_tester_helper.test_package_1',a_tags => 'suite1test1');
929+
l_results := ut3_tester_helper.main_helper.get_dbms_output_as_clob();
930+
--Assert
931+
ut.expect( l_results ).to_be_like( '%test_package_1%' );
932+
ut.expect( l_results ).to_be_like( '%test_package_1.test1%executed%' );
933+
ut.expect( l_results ).not_to_be_like( '%test_package_1.test2%' );
934+
ut.expect( l_results ).not_to_be_like( '%test_package_2%' );
935+
ut.expect( l_results ).not_to_be_like( '%test_package_3%' );
936+
end;
937+
938+
procedure run_proc_path_list_tag is
939+
l_results clob;
940+
begin
941+
ut3.ut.run(
942+
'ut3_tester_helper.test_package_1',
943+
ut3.ut_sonar_test_reporter(), a_source_files => ut3.ut_varchar2_list(),a_tags => 'suite1',
944+
a_test_files => ut3.ut_varchar2_list('tests/ut3_tester_helper.test_package_1.pkb',
945+
'tests/ut3_tester_helper.test_package_2.pkb',
946+
'tests/ut3_tester_helper.test_package_3.pkb')
947+
);
948+
l_results := ut3_tester_helper.main_helper.get_dbms_output_as_clob();
949+
--Assert
950+
ut.expect( l_results ).to_be_like( '%tests/ut3_tester_helper.test_package_1.pkb%' );
951+
ut.expect( l_results ).not_to_be_like( '%tests/ut3_tester_helper.test_package_2.pkb%' );
952+
ut.expect( l_results ).not_to_be_like( '%tests/ut3_tester_helper.test_package_3.pkb%' );
953+
end;
898954

899955
end;
900956
/

test/ut3_user/api/test_ut_run.pks

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ create or replace package test_ut_run is
168168
--%beforeall(create_ut3$user#_tests)
169169
--%afterall(drop_ut3$user#_tests)
170170

171-
--%test(Execute test by tag)
171+
--%test(Execute test by tag ut_run)
172172
procedure test_run_by_one_tag;
173173

174174
--%test( Execute suite by one tag)
@@ -194,6 +194,18 @@ create or replace package test_ut_run is
194194

195195
--%test(Execute suite test for duplicate list tags)
196196
procedure suite_duplicate_tag;
197+
198+
--%test(Run a package by name with non existing tag)
199+
procedure run_proc_pkg_name_no_tag;
200+
201+
--%test(Runs given package only with package name given as path and filter by tag)
202+
procedure run_proc_pkg_name_tag;
203+
204+
--%test(Runs all from given package with package name given as path and coverage file list with tag)
205+
procedure run_pkg_name_file_list_tag;
206+
207+
--%test(Runs tests from given paths with paths list and tag)
208+
procedure run_proc_path_list_tag;
197209

198210
--%endcontext
199211

0 commit comments

Comments
 (0)