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

Skip to content

Commit f087328

Browse files
authored
Merge pull request #154 from Pazus/feature/annotations_shorthand
Restored old syntax
2 parents 98beb1c + 94c0137 commit f087328

6 files changed

Lines changed: 120 additions & 15 deletions

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/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/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;

tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageByName.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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_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;

tests/ut_suite_manager/ut_suite_manager.configure_execution_by_path.PrepareRunnerForTheTopPackageProcedureByPath.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ begin
2626
l_test_proc := treat(l_test1_suite.items(1) as ut_test);
2727

2828
ut.expect(l_test_proc.name).to_equal('test2');
29+
ut.expect(l_test_proc.description).to_equal('Test2 from test package 1');
2930
ut.expect(l_test_proc.before_test is not null).to_be_true;
3031
ut.expect(l_test_proc.after_test is not null).to_be_true;
3132

0 commit comments

Comments
 (0)