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

Skip to content

Commit f335d46

Browse files
PazusPavel Kaplya
authored andcommitted
Configuration of the schema test suites based on the annotations in the schema's packages.
ut_metadata contains procedures to scan a package for pkg annotations and annotated procedures and defines necessary types. ut_suite_manager contains procedures to process ut_metadata annotations data and configure suites hierarchies based on them. For each package a suite is created. Also by setting %suitepackage annotation of the package like %suitepackage(parent.semiparent) one can define suites hierarchies. Suite configured for the package will be nested in the virtual suite "semiparent" which will also be nested in "parent" virtual suite. ut_suite_manager.config_schema procedure scans for annotations all the packages in the specified schema and configure whole schema suites (several root suites with nested suites if present). ut_suite_manager.run_schema_suites runs all suites for the schema reconfiguring it if needed ut_suite_manager.run_current_schema_suites does the same for the current schema ut_suite_manager is set to scan package and for annotations and generate schema suite hierarchy create suite and tests by parsing package spec Added suitesetup and suite teardown to the ut_test_suite object type Created example to demonstrate how such configuration operates.
1 parent b38a08a commit f335d46

12 files changed

Lines changed: 885 additions & 26 deletions

examples/RunAllExamples.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ prompt RunExampleTestThroughBaseClass
1313
@@RunExampleTestThroughBaseClass.sql
1414
prompt RunExampleTestSuiteWithCompositeReporter
1515
@@RunExampleTestSuiteWithCompositeReporter.sql
16+
prompt RunExampleTestAnnotationBasedForCurrentSchema
17+
@@RunExampleTestAnnotationBasedForCurrentSchema.sql
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--Shows how to create a test suite with the default reporter which is dbms_output
2+
--No tables are used for this.
3+
--Suite Management packages are when developed will make this easier.
4+
--Clear Screen
5+
Set Serveroutput On Size Unlimited format truncated
6+
set echo off
7+
--install the example unit test packages
8+
@@test_pkg1.pck
9+
@@test_pkg2.pck
10+
@@ut_custom_reporter.tps
11+
@@ut_custom_reporter.tpb
12+
13+
begin
14+
ut_suite_manager.run_cur_schema_suites_static(ut_custom_reporter(a_tab_size => 2));
15+
end;
16+
/
17+
18+
drop type ut_custom_reporter;
19+
drop package test_pkg1;
20+
drop package test_pkg2;

examples/test_pkg1.pck

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
create or replace package test_pkg1 is
2+
3+
/*
4+
This is the correct annotation
5+
*/
6+
-- %suite(Name of suite on test_pkg1)
7+
-- %suitepackage(all.globaltests)
8+
9+
/*
10+
Such comments are skipped
11+
12+
test name
13+
%test1
14+
%test2(name=123)
15+
%test3(name2=123,tete=123)
16+
%test4(name2=123,tete)
17+
*/
18+
/*
19+
This procedure is annotated incorrectly as no correct annotations specified
20+
Procedure is skipped while suite configuration
21+
*/
22+
--test name
23+
--%test1
24+
--%test2(name=123)
25+
---- %test3(name2=123,tete=123)
26+
---- asd %test4(name2=123,tete)
27+
-- t3 t4
28+
procedure foo;
29+
30+
-- %test(Name of test1)
31+
-- %testsetup(setup_test1)
32+
-- %testteardown(teardown_test1)
33+
procedure test1;
34+
35+
-- %test(Name of test2)
36+
procedure test2;
37+
38+
-- %suitesetup
39+
procedure global_setup;
40+
41+
procedure setup_test1;
42+
43+
procedure teardown_test1;
44+
45+
-- %setup
46+
procedure def_setup;
47+
48+
-- %teardown
49+
procedure def_teardown;
50+
51+
--%suiteteardown
52+
procedure global_teardown;
53+
54+
end;
55+
/
56+
create or replace package body test_pkg1 is
57+
58+
g_val1 number;
59+
g_val2 number;
60+
61+
procedure foo is
62+
begin
63+
null;
64+
end;
65+
66+
procedure test1 is
67+
begin
68+
ut_assert.are_equal(a_msg => '1 equals 1 check', a_expected => 1, a_actual => g_val1);
69+
end;
70+
71+
procedure test2 is
72+
begin
73+
--ut_assert.are_equal(a_msg => 'null equals null check', a_expected => to_number(null), a_actual => g_val1);
74+
ut_assert.are_equal(a_msg => '2 equals 2 check', a_expected => 2, a_actual => g_val2);
75+
end;
76+
77+
procedure global_setup is
78+
begin
79+
dbms_output.put_line('setup procedure of test_pkb1');
80+
end;
81+
82+
procedure setup_test1 is
83+
begin
84+
g_val1 := 1;
85+
end;
86+
87+
procedure teardown_test1 is
88+
begin
89+
g_val1 := null;
90+
end;
91+
92+
procedure def_setup is
93+
begin
94+
g_val2 := 2;
95+
end;
96+
97+
procedure def_teardown is
98+
begin
99+
g_val2 := null;
100+
end;
101+
102+
procedure global_teardown is
103+
begin
104+
dbms_output.put_line('global teardown procedure of test_pkb1');
105+
end;
106+
end test_pkg1;
107+
/

examples/test_pkg2.pck

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
create or replace package test_pkg2 is
2+
3+
/*
4+
This is the correct annotation
5+
*/
6+
-- %suite(Name of suite on test_pkg2)
7+
-- %suitepackage(all)
8+
9+
-- %test(Name of test1)
10+
procedure test1;
11+
12+
-- %test(Name of test2)
13+
procedure test2;
14+
15+
end;
16+
/
17+
create or replace package body test_pkg2 is
18+
19+
procedure test1 is
20+
begin
21+
ut_assert.are_equal(a_msg => '1 equals 1 check', a_expected => 1, a_actual => 1);
22+
end;
23+
24+
procedure test2 is
25+
begin
26+
ut_assert.are_equal(a_msg => '2 equals 2 check', a_expected => 2, a_actual => 2);
27+
end;
28+
29+
end test_pkg2;
30+
/

source/install.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
@@types/ut_composite_object.tps
44
@@types/ut_executable.tps
55
@@types/ut_assert_result.tps
6-
@@ut_metadata.pks
76
@@ut_assert.pks
87
@@types/ut_suite_reporter.tps
98
@@types/ut_reporters_list.tps
@@ -14,6 +13,8 @@
1413
@@types/ut_reporter_decorator.tps
1514
@@types/ut_dbms_output_suite_reporter.tps
1615
@@ut_utils.pks
16+
@@ut_metadata.pks
17+
@@ut_suite_manager.pks
1718

1819
@@ut_utils.pkb
1920
@@types/ut_assert_result.tpb
@@ -28,4 +29,5 @@
2829
@@types/ut_dbms_output_suite_reporter.tpb
2930
@@ut_metadata.pkb
3031
@@ut_assert.pkb
32+
@@ut_suite_manager.pkb
3133

source/test_pkgs.sql

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
CREATE OR REPLACE PACKAGE test_tt AS
2+
3+
-- %suite(Name of suite)
4+
-- %suitepackage(all.globaltests)
5+
6+
/*
7+
test name
8+
%test1
9+
%test2(name=123)
10+
%test3(name2=123,tete=123)
11+
%test4(name2=123,tete)
12+
*/
13+
--test name
14+
--%test1
15+
--%test2(name=123)
16+
---- %test3(name2=123,tete=123)
17+
---- asd %test4(name2=123,tete)
18+
-- t3 t4
19+
PROCEDURE foo;
20+
21+
-- %test(Name of test1)
22+
-- %testsetup(setup_test1)
23+
-- %testteardown(teardown_test1)
24+
PROCEDURE test1;
25+
26+
-- %test(Name of test2)
27+
PROCEDURE test2;
28+
29+
-- %suitesetup
30+
PROCEDURE setup;
31+
32+
PROCEDURE setup_test1;
33+
34+
PROCEDURE teardown_test1;
35+
36+
-- %setup
37+
procedure def_setup;
38+
39+
-- %teardown
40+
procedure def_teardown;
41+
42+
--%suiteteardown
43+
PROCEDURE global_teardown;
44+
45+
END;
46+
/
47+
48+
CREATE OR REPLACE PACKAGE test_tt2 AS
49+
50+
-- %suite(Name of suite)
51+
-- %suitepackage(all.globaltests)
52+
53+
54+
-- %test(Name of test2)
55+
PROCEDURE test2;
56+
57+
-- %suitesetup
58+
PROCEDURE setup;
59+
60+
-- %setup
61+
procedure def_setup;
62+
63+
-- %teardown
64+
procedure def_teardown;
65+
66+
--%suiteteardown
67+
PROCEDURE global_teardown;
68+
69+
END;
70+
/
71+
72+
CREATE OR REPLACE PACKAGE test_tt3 AS
73+
74+
-- %suite(Name of suite)
75+
-- %suitepackage(all)
76+
77+
78+
-- %test(Name of test2)
79+
PROCEDURE test2;
80+
81+
-- %suitesetup
82+
PROCEDURE setup;
83+
84+
-- %setup
85+
procedure def_setup;
86+
87+
-- %teardown
88+
procedure def_teardown;
89+
90+
--%suiteteardown
91+
PROCEDURE global_teardown;
92+
93+
END;
94+
/

source/test_tt.spc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
CREATE OR REPLACE PACKAGE test_tt AS
2+
3+
-- %suite(Name of suite)
4+
-- %suitepackage(all.globaltests)
5+
6+
/*
7+
test name
8+
%test1
9+
%test2(name=123)
10+
%test3(name2=123,tete=123)
11+
%test4(name2=123,tete)
12+
*/
13+
--test name
14+
--%test1
15+
--%test2(name=123)
16+
---- %test3(name2=123,tete=123)
17+
---- asd %test4(name2=123,tete)
18+
-- t3 t4
19+
PROCEDURE foo;
20+
21+
-- %test(Name of test1)
22+
-- %testsetup(setup_test1)
23+
-- %testteardown(teardown_test1)
24+
PROCEDURE test1;
25+
26+
-- %test(Name of test2)
27+
PROCEDURE test2;
28+
29+
-- %suitesetup
30+
PROCEDURE setup;
31+
32+
PROCEDURE setup_test1;
33+
34+
PROCEDURE teardown_test1;
35+
36+
-- %setup
37+
procedure def_setup;
38+
39+
-- %teardown
40+
procedure def_teardown;
41+
42+
--%suiteteardown
43+
PROCEDURE global_teardown;
44+
45+
END;
46+
/

source/uninstall.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
drop package ut_suite_manager;
2+
13
drop package ut_assert;
24

35
drop package ut_metadata;

0 commit comments

Comments
 (0)