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

Skip to content

Commit d1ac86b

Browse files
committed
Merge remote-tracking branch 'remotes/upstream/version3' into feature/suite_base_v2
# Conflicts: # tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql
2 parents 8d2fd9a + f087328 commit d1ac86b

11 files changed

Lines changed: 226 additions & 39 deletions

client_source/grant_public.sql

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ grant execute on &ut3_owner .ut_teamcity_reporter to public;
2828
grant execute on &ut3_owner .ut_documentation_reporter to public;
2929
grant execute on &ut3_owner .ut_reporters to public;
3030

31-
create or replace public synonym be_between for &ut3_owner .ut_be_between;
32-
create or replace public synonym be_false for &ut3_owner .ut_be_false;
33-
create or replace public synonym be_greater_or_equal for &ut3_owner .ut_be_greater_or_equal;
34-
create or replace public synonym be_greater_than for &ut3_owner .ut_be_greater_than;
35-
create or replace public synonym be_less_or_equal for &ut3_owner .ut_be_less_or_equal;
36-
create or replace public synonym be_less_than for &ut3_owner .ut_be_less_than;
37-
create or replace public synonym be_like for &ut3_owner .ut_be_like;
38-
create or replace public synonym be_not_null for &ut3_owner .ut_be_not_null;
39-
create or replace public synonym be_null for &ut3_owner .ut_be_null;
40-
create or replace public synonym be_true for &ut3_owner .ut_be_true;
41-
create or replace public synonym equal for &ut3_owner .ut_equal;
42-
create or replace public synonym match for &ut3_owner .ut_match;
43-
create or replace public synonym ut for &ut3_owner .ut;
44-
create or replace public synonym ut_runner for &ut3_owner .ut_runner;
45-
create or replace public synonym ut_teamcity_reporter for &ut3_owner .ut_teamcity_reporter;
46-
create or replace public synonym ut_documentation_reporter for &ut3_owner .ut_documentation_reporter;
47-
create or replace public synonym ut_reporters for &ut3_owner .ut_reporters;
31+
create public synonym be_between for &ut3_owner .ut_be_between;
32+
create public synonym be_false for &ut3_owner .ut_be_false;
33+
create public synonym be_greater_or_equal for &ut3_owner .ut_be_greater_or_equal;
34+
create public synonym be_greater_than for &ut3_owner .ut_be_greater_than;
35+
create public synonym be_less_or_equal for &ut3_owner .ut_be_less_or_equal;
36+
create public synonym be_less_than for &ut3_owner .ut_be_less_than;
37+
create public synonym be_like for &ut3_owner .ut_be_like;
38+
create public synonym be_not_null for &ut3_owner .ut_be_not_null;
39+
create public synonym be_null for &ut3_owner .ut_be_null;
40+
create public synonym be_true for &ut3_owner .ut_be_true;
41+
create public synonym equal for &ut3_owner .ut_equal;
42+
create public synonym match for &ut3_owner .ut_match;
43+
create public synonym ut for &ut3_owner .ut;
44+
create public synonym ut_runner for &ut3_owner .ut_runner;
45+
create public synonym ut_teamcity_reporter for &ut3_owner .ut_teamcity_reporter;
46+
create public synonym ut_documentation_reporter for &ut3_owner .ut_documentation_reporter;
47+
create public synonym ut_reporters for &ut3_owner .ut_reporters;

docs/userguide/annotations.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Annotations
22

33
Annotations provide a way to configure tests and suites in a declarative way similar to modern OOP languages.
4-
The annotation list is based on jUnit 5 implementation.
4+
The annotation list is based on moder testing framework such as jUnit 5, RSpec.
55

6-
# Example
7-
Let's say we have the test package like this:
6+
Annotations allow to configure test infrastructure in a declarative way without anything stored in tables or config files. The framework runner scans the schema for all the suitable annotated packages, automatically configures suites, forms hierarchy from then and executes them.
7+
8+
# Example of annotated package
89
```
910
create or replace package test_pkg is
1011
11-
-- %suite
12-
-- %displayname(Name of suite)
12+
-- %suite(Name of suite)
1313
-- %suitepath(all.globaltests)
1414
1515
-- %beforeall
@@ -24,16 +24,19 @@ create or replace package test_pkg is
2424
-- %displayname(Name of test1)
2525
procedure test1;
2626
27-
-- %test
28-
-- %displayname(Name of test2)
27+
-- %test(Name of test2)
2928
-- %beforetest(setup_test1)
3029
-- %aftertest(teardown_test1)
3130
procedure test2;
3231
3332
-- %test
3433
-- %displayname(Name of test3)
35-
-- %testtype(smoke)
34+
-- %disable
3635
procedure test3;
36+
37+
-- %test(Name of test4)
38+
-- %rollback(manual)
39+
procedure test4;
3740
3841
procedure setup_test1;
3942
@@ -52,17 +55,15 @@ end test_pkg;
5255

5356
| Annotation |Level| Describtion |
5457
| --- | --- | --- |
55-
| `%suite` | Package | Marks package to be a suite of tests This way all testing packages might be found in a schema. |
58+
| `%suite(<description>)` | Package | Marks package to be a suite of tests This way all testing packages might be found in a schema. Optional schema discription can by provided, similar to `%displayname` annotation. |
5659
| `%suitepath(<path>)` | Package | Similar to java package. The annotation allows logical grouping of suites into hierarcies. |
57-
| `%displayname(<description>)` | Package/procedure | Human-familiar describtion of the suite/test. `%displayname(Name of the suite/test)` |
58-
| `%test` | Procedure | Denotes that a method is a test method. |
60+
| `%displayname(<description>)` | Package/procedure | Human-familiar describtion of the suite/test. Syntax is based on jUnit annotation: `%displayname(Name of the suite/test)` |
61+
| `%test(<description>)` | Procedure | Denotes that a method is a test method. Optional test discription can by provided, similar to `%displayname` annotation. |
5962
| `%beforeall` | Procedure | Denotes that the annotated procedure should be executed once before all elements of the current suite. |
6063
| `%afterall` | Procedure | Denotes that the annotated procedure should be executed once after all elements of the current suite. |
6164
| `%beforeeach` | Procedure | Denotes that the annotated procedure should be executed before each `%test` method in the current suite. |
6265
| `%aftereach` | Procedure | Denotes that the annotated procedure should be executed after each `%test` method in the current suite. |
6366
| `%beforetest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed before the annotated `%test` procedure. |
6467
| `%aftertest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed after the annotated `%test` procedure. |
6568
| `%rollback(<type>)` | Package/procedure | Configure transaction control behaviour (type). Supported values: `auto`(default) - rollback to savepoint (before the test/suite setup) is issued after each test/suite teardown; `manual` - rollback is never issued automatically. Property can be overridden for child element (test in suite) |
66-
| `%disable` | Package/procedure | Used to disable a suite or a test |
67-
68-
Annotations allow us to configure test infrastructure in a declarative way without anything stored in tables or config files. Suite manager would scan the schema for all the suitable packages, automatically configure suites and execute them. This can be simplified to the situation when you just ran suite manager over a schema for the defined types of tests and reporters and everything goes automatically. This is going to be convenient to be executed from CI tools using standard reporting formats.
69+
| `%disable` | Package/procedure | Used to disable a suite or a test |

readme.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,76 @@ The following table is a work in progress right now, and **will** change. If y
6767

6868
<sup>3</sup> Test execution comparison is in a single call so the results are combined. We know it was always possible group in any way with multiple calls. But that may not be desired under CI system where you want a single JUnit XML Output.
6969

70+
# Annotations
71+
72+
Annotations provide a way to configure tests and suites in a declarative way similar to modern OOP languages.
73+
The annotation list is based on moder testing framework such as jUnit 5, RSpec.
74+
75+
Annotations allow to configure test infrastructure in a declarative way without anything stored in tables or config files. The framework runner scans the schema for all the suitable annotated packages, automatically configures suites, forms hierarchy from then and executes them.
76+
77+
# Example of annotated package
78+
```
79+
create or replace package test_pkg is
80+
81+
-- %suite(Name of suite)
82+
-- %suitepath(all.globaltests)
83+
84+
-- %beforeall
85+
procedure globalsetup;
86+
87+
-- %afterall
88+
procedure global_teardown;
89+
90+
/* Such comments are allowed */
91+
92+
-- %test
93+
-- %displayname(Name of test1)
94+
procedure test1;
95+
96+
-- %test(Name of test2)
97+
-- %beforetest(setup_test1)
98+
-- %aftertest(teardown_test1)
99+
procedure test2;
100+
101+
-- %test
102+
-- %displayname(Name of test3)
103+
-- %disable
104+
procedure test3;
105+
106+
-- %test(Name of test4)
107+
-- %rollback(manual)
108+
procedure test4;
109+
110+
procedure setup_test1;
111+
112+
procedure teardown_test1;
113+
114+
-- %beforeeach
115+
procedure setup;
116+
117+
-- %aftereach
118+
procedure teardown;
119+
120+
end test_pkg;
121+
```
122+
123+
#Annotations meaning
124+
125+
| Annotation |Level| Describtion |
126+
| --- | --- | --- |
127+
| `%suite(<description>)` | Package | Marks package to be a suite of tests This way all testing packages might be found in a schema. Optional schema discription can by provided, similar to `%displayname` annotation. |
128+
| `%suitepath(<path>)` | Package | Similar to java package. The annotation allows logical grouping of suites into hierarcies. |
129+
| `%displayname(<description>)` | Package/procedure | Human-familiar describtion of the suite/test. Syntax is based on jUnit annotation: `%displayname(Name of the suite/test)` |
130+
| `%test(<description>)` | Procedure | Denotes that a method is a test method. Optional test discription can by provided, similar to `%displayname` annotation. |
131+
| `%beforeall` | Procedure | Denotes that the annotated procedure should be executed once before all elements of the current suite. |
132+
| `%afterall` | Procedure | Denotes that the annotated procedure should be executed once after all elements of the current suite. |
133+
| `%beforeeach` | Procedure | Denotes that the annotated procedure should be executed before each `%test` method in the current suite. |
134+
| `%aftereach` | Procedure | Denotes that the annotated procedure should be executed after each `%test` method in the current suite. |
135+
| `%beforetest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed before the annotated `%test` procedure. |
136+
| `%aftertest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed after the annotated `%test` procedure. |
137+
| `%rollback(<type>)` | Package/procedure | Configure transaction control behaviour (type). Supported values: `auto`(default) - rollback to savepoint (before the test/suite setup) is issued after each test/suite teardown; `manual` - rollback is never issued automatically. Property can be overridden for child element (test in suite) |
138+
| `%disable` | Package/procedure | Used to disable a suite or a test |
139+
70140

71141
__Primary Directories__
72142

source/core/annotations/ut_annotations.pkb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ create or replace package body ut_annotations as
1818

1919

2020
function delete_multiline_comments(a_source in clob) return clob is
21-
l_tmp_clob clob;
2221
begin
2322

2423
/* l_tmp_clob := regexp_replace(srcstr => a_source
@@ -135,9 +134,9 @@ create or replace package body ut_annotations as
135134
l_package_comments varchar2(32767);
136135
begin
137136
l_package_comments := regexp_substr(srcstr => a_source
138-
,pattern => '^\s*(CREATE\s+(OR\s+REPLACE)?(\s+(NON)?EDITIONABLE)?\s+)?PACKAGE .*?\s+(AS|IS)\s+((.*?{COMMENT#\d+}\s?)+)'
137+
,pattern => '^\s*(CREATE\s+(OR\s+REPLACE)?(\s+(NON)?EDITIONABLE)?\s+)?PACKAGE\s[^;]*?(\s+(AS|IS)\s+)((.*?{COMMENT#\d+}\s?)+)'
139138
,modifier => 'i'
140-
,subexpression => 6);
139+
,subexpression => 7);
141140

142141
-- parsing for package annotations
143142
return
@@ -329,7 +328,7 @@ create or replace package body ut_annotations as
329328

330329
l_source := ut_metadata.get_package_spec_source(a_owner_name, a_name);
331330

332-
if l_source is null then
331+
if l_source is null or sys.dbms_lob.getlength(l_source)=0 then
333332
return null;
334333
else
335334
return parse_package_annotations(l_source);

source/core/ut_suite_manager.pkb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ create or replace package body ut_suite_manager is
5555

5656
if l_annotation_data.package_annotations.exists('displayname') then
5757
l_suite_name := ut_annotations.get_annotation_param(l_annotation_data.package_annotations('displayname'), 1);
58+
elsif l_annotation_data.package_annotations('suite').count>0 then
59+
l_suite_name := ut_annotations.get_annotation_param(l_annotation_data.package_annotations('suite'), 1);
5860
end if;
5961

6062
if l_annotation_data.package_annotations.exists('suitepath') then
@@ -129,6 +131,8 @@ create or replace package body ut_suite_manager is
129131

130132
if l_proc_annotations.exists('displayname') then
131133
l_displayname := ut_annotations.get_annotation_param(l_proc_annotations('displayname'), 1);
134+
elsif l_proc_annotations('test').count>0 then
135+
l_displayname := ut_annotations.get_annotation_param(l_proc_annotations('test'), 1);
132136
end if;
133137

134138
if l_proc_annotations.exists('rollback') then

tests/RunAll.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ create table ut$test_table (val varchar2(1));
6767
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseComplexPackage.sql
6868
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageAndProcedureLevelAnnotations.sql
6969
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotation.sql
70+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationAccessibleBy.sql
71+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationMultilineDeclare.sql
7072
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithKeyValue.sql
7173
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithMultilineComment.sql
7274
@@lib/RunTest.sql ut_metadata/ut_metadata.form_name.TrimStandaloneProgramName.sql

tests/helpers/test_package_1.pck

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ create or replace package test_package_1 is
1212
procedure global_teardown;
1313

1414
--%test
15+
--%displayname(Test1 from test package 1)
1516
procedure test1;
1617

17-
--%test
18+
--%test(Test2 from test package 1)
1819
--%beforetest(test2_setup)
1920
--%aftertest(test2_teardown)
2021
procedure test2;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
PROMPT Parse package level annotations Accessible by
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt accessible by (foo) AS
12+
-- %suite
13+
-- %displayname(Name of suite)
14+
-- %suitepath(all.globaltests)
15+
16+
procedure foo;
17+
END;';
18+
19+
--Act
20+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
21+
22+
--Assert
23+
l_ann_param := null;
24+
l_ann_param.val := 'Name of suite';
25+
l_expected.package_annotations('suite') := cast( null as ut_annotations.tt_annotation_params);
26+
l_expected.package_annotations('displayname')(1) := l_ann_param;
27+
28+
l_ann_param := null;
29+
l_ann_param.val := 'all.globaltests';
30+
l_expected.package_annotations('suitepath')(1) := l_ann_param;
31+
32+
check_annotation_parsing(l_expected, l_parsing_result);
33+
34+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
35+
:test_result := ut_utils.tr_success;
36+
end if;
37+
38+
end;
39+
/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
PROMPT Parse package level annotations with multiline declaration
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt
12+
ACCESSIBLE BY (calling_proc)
13+
authid current_user
14+
AS
15+
-- %suite
16+
-- %displayname(Name of suite)
17+
-- %suitepath(all.globaltests)
18+
19+
procedure foo;
20+
END;';
21+
22+
--Act
23+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
24+
25+
--Assert
26+
l_ann_param := null;
27+
l_ann_param.val := 'Name of suite';
28+
l_expected.package_annotations('suite') := cast( null as ut_annotations.tt_annotation_params);
29+
l_expected.package_annotations('displayname')(1) := l_ann_param;
30+
31+
l_ann_param := null;
32+
l_ann_param.val := 'all.globaltests';
33+
l_expected.package_annotations('suitepath')(1) := l_ann_param;
34+
35+
check_annotation_parsing(l_expected, l_parsing_result);
36+
37+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
38+
:test_result := ut_utils.tr_success;
39+
end if;
40+
41+
end;
42+
/

tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ declare
55
c_path varchar2(100) := USER||'.test_package_1';
66
l_objects_to_run ut_suite_items;
77

8-
l_test0_suite ut_logical_suite;
9-
l_test1_suite ut_logical_suite;
10-
l_test2_suite ut_logical_suite;
8+
l_test0_suite ut_suite;
9+
l_test1_suite ut_suite;
10+
l_test2_suite ut_suite;
1111
begin
1212
--Act
1313
l_objects_to_run := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(c_path));
@@ -22,6 +22,22 @@ begin
2222

2323
ut.expect(l_test1_suite.name).to_equal('test_package_1');
2424
ut.expect(l_test1_suite.items.count).to_equal(3);
25+
ut.expect(l_test1_suite.before_each is not null).to_be_true;
26+
27+
ut.expect(l_test1_suite.items(1).name).to_equal('test1');
28+
ut.expect(l_test1_suite.items(1).description).to_equal('Test1 from test package 1');
29+
ut.expect(treat(l_test1_suite.items(1) as ut_test).before_test.is_defined).to_be_false;
30+
ut.expect(treat(l_test1_suite.items(1) as ut_test).after_test.is_defined).to_be_false;
31+
ut.expect(treat(l_test1_suite.items(1) as ut_test).ignore_flag).to_equal(0);
32+
33+
ut.expect(l_test1_suite.items(2).name).to_equal('test2');
34+
ut.expect(l_test1_suite.items(2).description).to_equal('Test2 from test package 1');
35+
ut.expect(treat(l_test1_suite.items(2) as ut_test).before_test.is_defined).to_be_true;
36+
ut.expect(treat(l_test1_suite.items(2) as ut_test).after_test.is_defined).to_be_true;
37+
ut.expect(treat(l_test1_suite.items(2) as ut_test).ignore_flag).to_equal(0);
38+
39+
-- temporary behavior.
40+
-- decided that when executed by package, not path, only that package has to execute
2541
l_test2_suite := treat(l_test1_suite.items(3) as ut_logical_suite);
2642

2743
ut.expect(l_test2_suite.name).to_equal('test_package_2');
@@ -30,6 +46,18 @@ begin
3046

3147
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
3248
:test_result := ut_utils.tr_success;
49+
else
50+
declare
51+
l_results ut_assert_results;
52+
begin
53+
l_results := ut_assert_processor.get_asserts_results;
54+
for i in 1..l_results.count loop
55+
if l_results(i).result > ut_utils.tr_success then
56+
dbms_output.put_line(l_results(i).get_result_clob);
57+
end if;
58+
end loop;
59+
end;
60+
3361
end if;
3462

3563
end;

0 commit comments

Comments
 (0)