Skip to content

Commit 6449754

Browse files
committed
annotations redesign
1 parent d6c4ebb commit 6449754

22 files changed

+2101
-1493
lines changed

client_source/sqlplus/ut_run.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Parameters:
1414
-p=ut_path(s)- A path or a comma separated list of paths to unit test to be executed.
1515
The path can be in one of the following formats:
1616
schema[.package[.procedure]]
17-
schema:suitepacakge[.suitepackage[.suitepackage][...]][.procedure]
17+
schema:suite[.suite[.suite][...]][.procedure]
1818
Both formats can be mixed in the comma separated list.
1919
If only schema is provided, then all suites owner by that schema (user) are executed.
2020
If -p is omitted, the current schema is used.

docs/userguide/annotations.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
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.
45

56
# Example
67
Let's say we have the test package like this:
78
```
89
create or replace package test_pkg is
910
10-
-- %suite(Name of suite)
11-
-- %suitepackage(all.globaltests)
12-
-- %suitetype(critical)
11+
-- %suite
12+
-- %displayname(Name of suite)
13+
-- %suitepath(all.globaltests)
1314
14-
-- %suitesetup
15+
-- %beforeall
1516
procedure globalsetup;
1617
17-
-- %suiteteardown
18+
-- %afterall
1819
procedure global_teardown;
1920
2021
/* Such comments are allowed */
2122
22-
-- %test(Name of test1)
23-
-- %testtype(smoke)
23+
-- %test
24+
-- %displayname(Name of test1)
2425
procedure test1;
2526
26-
-- %test(Name of test2)
27-
-- %testsetup(setup_test1)
28-
-- %testteardown(teardown_test1)
27+
-- %test
28+
-- %displayname(Name of test2)
29+
-- %beforetest(setup_test1)
30+
-- %aftertest(teardown_test1)
2931
procedure test2;
3032
31-
-- %test(Name of test3)
33+
-- %test
34+
-- %displayname(Name of test3)
3235
-- %testtype(smoke)
3336
procedure test3;
3437
3538
procedure setup_test1;
3639
3740
procedure teardown_test1;
3841
39-
-- %setup
42+
-- %beforeeach
4043
procedure setup;
4144
42-
-- %teardown
45+
-- %aftereach
4346
procedure teardown;
4447
4548
end test_pkg;
4649
```
4750

4851
#Annotations meaning
4952

50-
Annotation | Meaning
51-
------------ | -------------
52-
%suite | Marks package to be a suite with it procedures as tests. This way all testing packages might be found in the schema. Parameter of the annotation is the Suite name
53-
%suitepackage | Similar to java package. The example suite should be put as an element of the "globaltests" suite which is an element of the "all" suite. This allows one to execute "glovaltests" suite which would recursively run all the child suites including this one.
54-
%suitetype | The way for suite to have something like a type. One might collect suites based on the subject of tests (a system module for example). There might be critical tests to run every time and more covering but slow tests. This technique allows to configure something like "fast" testing.
55-
%setup | Marks procedure as a default setup procedure for the suite.
56-
%teardown | Marks procedure as a default teardown procedure for the suite.
57-
%test | Marks procedure as a test. Parameter is a name of the test
58-
%testtype | Another way to tag tests to filter afterwards
59-
%testsetup | Marks that special setup procedure has to be run before the test instead of the default one
60-
%testteardown | Marks that special teardown procedure has to be run before the test instead of the default one
61-
%suitesetup | Procedure with executes once at the beginning of the suite and doesn't executes before each test
62-
%suiteteardown | Procedure with executes once after the execution of the last test in the suite.
53+
| Annotation |Level| Describtion |
54+
| --- | --- | --- |
55+
| `%suite` | Package | Marks package to be a suite of tests This way all testing packages might be found in a schema. |
56+
| `%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. |
59+
| `%beforeall` | Procedure | Denotes that the annotated procedure should be executed before all `%test` methods in the current suite. |
60+
| `%afterall` | Procedure | Denotes that the annotated procedure should be executed after all `%test` methods in the current suite. |
61+
| `%beforeeach` | Procedure | Denotes that the annotated procedure should be executed before each `%test` method in the current suite. |
62+
| `%aftereach` | Procedure | Denotes that the annotated procedure should be executed after each `%test` method in the current suite. |
63+
| `%beforetest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed before the annotated `%test` procedure. |
64+
| `%aftertest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed after the annotated `%test` procedure. |
65+
| `%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 |
6367

6468
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.
65-

examples/RunWithDocumentationReporter.sql

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ set linesize 10000
33
set echo off
44

55
create or replace package demo_doc_reporter1 is
6-
-- %suite(Demo of documentation reporter)
7-
-- %test(A passing test sample)
6+
-- %suite
7+
-- %displayname(Demo of documentation reporter)
8+
9+
-- %test
10+
-- %displayname(A passing test sample)
811
procedure passing_test;
912
-- %test
1013
procedure test_without_name;
11-
-- %test(A failing test exsample)
14+
-- %test
15+
-- %displayname(A failing test exsample)
1216
procedure failing_test;
1317
-- %test
1418
procedure failing_no_name;
15-
-- %test(repoting exception)
19+
-- %test
20+
-- %displayname(repoting exception)
1621
procedure failing_exception_raised;
1722
end;
1823
/
@@ -43,8 +48,11 @@ end;
4348
/
4449

4550
create or replace package demo_doc_reporter2 is
46-
-- %suite(A suite package without body)
47-
-- %test(A test)
51+
-- %suite
52+
-- %displayname(A suite package without body)
53+
54+
-- %test
55+
-- %displayname(A test)
4856
procedure test1;
4957
-- %test
5058
procedure test2;
@@ -53,9 +61,12 @@ end;
5361

5462
create or replace package suite_package_without_name is
5563
-- %suite
56-
-- %test(A passing test sample)
64+
65+
-- %test
66+
-- %displayname(A passing test sample)
5767
procedure passing_test1;
58-
-- %test(A passing test sample)
68+
-- %test
69+
-- %displayname(A passing test sample)
5970
procedure passing_test2;
6071
end;
6172
/

examples/award_bonus/test_award_bonus.pkg

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
create or replace package test_award_bonus as
22

3-
-- %suite(Award bonus)
3+
-- %suite
4+
-- %displayname(Award bonus)
45

5-
-- %test(Sets new salary as pct commision * sales amount)
6-
-- %testsetup(add_test_employee)
6+
-- %test
7+
-- %displayname(Sets new salary as pct commision * sales amount)
8+
-- %beforetest(add_test_employee)
79
procedure update_employee_salary;
810

9-
-- %test(Raises exception if null bonus is passed)
10-
-- %testsetup(add_employee_with_null_comm)
11+
-- %test
12+
-- %displayname(Raises exception if null bonus is passed)
13+
-- %beforetest(add_employee_with_null_comm)
1114
procedure fail_on_null_bonus;
1215

1316
procedure add_test_employee;
@@ -16,7 +19,6 @@ create or replace package test_award_bonus as
1619

1720
end;
1821
/
19-
2022
create or replace package body test_award_bonus as
2123

2224
gc_test_employee constant integer := -1;

examples/between_string/test_betwnstr.pkg

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
create or replace package test_betwnstr as
22

3-
-- %suite(Between string function)
3+
-- %suite
4+
-- %displayname(Between string function)
45

5-
-- %test(Returns substring from start position to end position)
6+
-- %test
7+
-- %displayname(Returns substring from start position to end position)
68
procedure normal_case;
79

8-
-- %test(Returns substring when start position is zero)
10+
-- %test
11+
-- %displayname(Returns substring when start position is zero)
912
procedure zero_start_position;
1013

11-
-- %test(Returns string until end if end position is greated than string length)
14+
-- %test
15+
-- %displayname(Returns string until end if end position is greated than string length)
1216
procedure big_end_position;
1317

14-
-- %test(Returns null for null inlut srting value)
18+
-- %test
19+
-- %displayname(Returns null for null inlut srting value)
1520
procedure null_string;
1621
end;
1722
/
18-
1923
create or replace package body test_betwnstr as
2024

2125
procedure normal_case is

examples/demo_expectations.pck

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,70 @@
11
create or replace package demo_expectations is
22

3-
-- %suite(Demoing asserts)
3+
-- %suite
4+
-- %displayname(Demoing asserts)
45

5-
-- %test(demo of expectations with nulls)
6+
-- %test
7+
-- %displayname(demo of expectations with nulls)
68
procedure demo_nulls_on_expectations;
79

8-
-- %test(demo of failure for to_equal expectation on value mismatch)
10+
-- %test
11+
-- %displayname(demo of failure for to_equal expectation on value mismatch)
912
procedure demo_to_equal_failure;
1013

11-
-- %test(demo of failure for to_equal expectation on data type mismatch)
14+
-- %test
15+
-- %displayname(demo of failure for to_equal expectation on data type mismatch)
1216
procedure demo_to_equal_failure_types;
1317

14-
-- %test(demo of success for to_equal expectation)
18+
-- %test
19+
-- %displayname(demo of success for to_equal expectation)
1520
procedure demo_to_equal_success;
1621

17-
-- %test(demo of failure for to_be_true and to_be_false expectation)
22+
-- %test
23+
-- %displayname(demo of failure for to_be_true and to_be_false expectation)
1824
procedure demo_to_be_true_false_failure;
1925

20-
-- %test(demo of success for to_be_true and to_be_false expectation)
26+
-- %test
27+
-- %displayname(demo of success for to_be_true and to_be_false expectation)
2128
procedure demo_to_be_true_false_success;
2229

23-
-- %test(demo of failure for to_be_null expectation )
30+
-- %test
31+
-- %displayname(demo of failure for to_be_null expectation )
2432
procedure demo_to_be_null_failure;
2533

26-
-- %test(demo of failure for to_be_null expectation )
34+
-- %test
35+
-- %displayname(demo of failure for to_be_null expectation )
2736
procedure demo_to_be_null_success;
2837

29-
-- %test(demo of success for to_be_not_null expectation )
38+
-- %test
39+
-- %displayname(demo of success for to_be_not_null expectation )
3040
procedure demo_to_be_not_null_failure;
3141

32-
-- %test(demo of success for to_be_not_null expectation)
42+
-- %test
43+
-- %displayname(demo of success for to_be_not_null expectation)
3344
procedure demo_to_be_not_null_success;
3445

35-
-- %test(demo of failure for to_match expectation)
46+
-- %test
47+
-- %displayname(demo of failure for to_match expectation)
3648
procedure demo_to_match_failure;
3749

38-
-- %test(demo of success for to_match expectation)
50+
-- %test
51+
-- %displayname(demo of success for to_match expectation)
3952
procedure demo_to_match_success;
4053

41-
-- %test(demo of failure for to_be_like expectation)
54+
-- %test
55+
-- %displayname(demo of failure for to_be_like expectation)
4256
procedure demo_to_be_like_failure;
4357

44-
-- %test(demo of success for to_be_like expectation)
58+
-- %test
59+
-- %displayname(demo of success for to_be_like expectation)
4560
procedure demo_to_be_like_success;
4661

47-
-- %test(demo of failure for not_to expectations)
62+
-- %test
63+
-- %displayname(demo of failure for not_to expectations)
4864
procedure demo_not_to_failure;
4965

50-
-- %test(demo of success for not_to expectations)
66+
-- %test
67+
-- %displayname(demo of success for not_to expectations)
5168
procedure demo_not_to_success;
5269

5370
end;

examples/demo_of_expectations/demo_equal_matcher.sql

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,39 @@ create or replace type demo_departments as table of demo_department
1313

1414
create or replace package demo_equal_matcher as
1515

16-
-- %suite(Equal matcher)
17-
-- %suitepackage(org.utplsql.v3.demo.matchers)
16+
-- %suite
17+
-- %displayname(Equal matcher)
18+
-- %suitepath(org.utplsql.v3.demo.matchers)
1819

1920
-- TODO this should go into context(compare_objects, Comparing objects)
2021
-- %context(compare_objects, Comparing objects)
2122

22-
-- %test(Gives success when comparing identical objects containing identical data)
23+
-- %test
24+
-- %displayname(Gives success when comparing identical objects containing identical data)
2325
procedure object_compare_success;
2426

25-
-- %test(Gives failure when comparing to a null actual)
27+
-- %test
28+
-- %displayname(Gives failure when comparing to a null actual)
2629
procedure object_compare_null_actual;
2730

28-
-- %test(Gives failure when comparing to a null expected)
31+
-- %test
32+
-- %displayname(Gives failure when comparing to a null expected)
2933
procedure object_compare_null_expected;
3034

31-
-- %test(Gives success when comparing null actual to a null expected)
35+
-- %test
36+
-- %displayname(Gives success when comparing null actual to a null expected)
3237
procedure object_compare_null_both_ok;
3338

34-
-- %test(Gives failure when comparing null actual to a null expected, setting null equal to false)
39+
-- %test
40+
-- %displayname(Gives failure when comparing null actual to a null expected, setting null equal to false)
3541
procedure object_compare_null_both_fail;
3642

37-
-- %test(Gives failure when comparing identical objects containing different data)
43+
-- %test
44+
-- %displayname(Gives failure when comparing identical objects containing different data)
3845
procedure object_compare_different_data;
3946

40-
-- %test(Gives failure when comparing different objects containing identical data)
47+
-- %test
48+
-- %displayname(Gives failure when comparing different objects containing identical data)
4149
procedure object_compare_different_type;
4250

4351
-- %end_context

0 commit comments

Comments
 (0)