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

Skip to content

Commit a171f5f

Browse files
committed
Addressed review comments.
1 parent 2b29c61 commit a171f5f

5 files changed

Lines changed: 92 additions & 37 deletions

File tree

docs/index.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,39 @@
33
utPLSQL is a Unit Testing framework for Oracle PL/SQL.
44
The framework follows industry standards and best patterns of modern Unit Testing frameworks like [JUnit](http://junit.org/junit4/) and [RSpec](http://rspec.info/)
55

6+
- User Guide
7+
- [Installation](userguide/install.md)
8+
- [Getting Started](userguide/getting-started.md)
9+
- [Annotations](userguide/annotations.md)
10+
- [Expectations](userguide/expectations.md)
11+
- [Running unit tests](userguide/running-unit-tests.md)
12+
- [Using the ut_run script](userguide/ut_run-script.md)
13+
- [Testing best pracitces](userguide/best-practices.md)
14+
- [Upgrade utPLSQL](userguide/upgrade.md)
15+
- Reporting
16+
- [Using reporters](userguide/reporters.md)
17+
- [Reporting errors](userguide/exception-reporting.md)
18+
- [Code coverage](userguide/coverage.md)
19+
- About
20+
- [Project Details](about/project-details.md)
21+
- [License](about/license.md)
22+
- [Support](about/support.md)
23+
- [Authors](about/authors.md)
24+
- [Contributing](about/CONTRIBUTING.md)
25+
26+
627
#Three steps
728
With just three simple steps you can define and run your unit tests for PLSQL code.
829

930
1. Install the utPLSQL framework
10-
2. Create Unit Tests to cover the code
31+
2. Create Unit Tests to for the code
1132
3. Run the tests
1233

1334
Here is how you can simply create tested code, unit tests and execute the tests using SQL Developer
1435

1536
![3_steps](images/3_steps_to_run_utPLSQL.gif)
1637

17-
Check out the sections on [annotations](userguide/annotations.md) and [expectations](userguide/expectations.md) to see how to define your tests
38+
Check out the sections on [annotations](userguide/annotations.md) and [expectations](userguide/expectations.md) to see how to define your tests.
1839

1940

2041
# Command line

docs/userguide/expectations.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ end;
1212

1313
Expectation is a set of the expected value(s), actual values(s) and the matcher(s) to run on those values.
1414

15-
Matcher is defining the comparison operation to be performed on expected and actual values.
15+
Matcher is defining the comparison operation to be performed on expected and actual values.
16+
Pseudo-code:
17+
```sql
18+
ut.expect( a_actual {data-type} ).to_( {matcher} );
19+
ut.expect( a_actual {data-type} ).not_to( {matcher} );
20+
```
21+
1622

1723
# Matchers
1824
utPLSQL provides following matchers to perform checks on the expected and actual values.
@@ -33,17 +39,23 @@ utPLSQL provides following matchers to perform checks on the expected and actual
3339
## be_between
3440
Validates that the actual value is between the lower and upper bound.
3541

36-
Usage:
42+
Example:
3743
```sql
38-
ut.expect( a_actual {mulitple data-types} ).to_( be_between( a_lower_bound {mulitple data-types}, a_upper_bound {mulitple data-types}) );
44+
exec ut.expect( a_actual => 3 ).to_( be_between( a_lower_bound => 1, a_upper_bound => 3 ) );
45+
exec ut.expect( 3 ).to_( be_between( 1, 3 ) );
3946
```
4047

4148
## be_empty
42-
Unary matcher that validates if the provided dataset is empty.
49+
Unary matcher that validates if the provided data-set is empty.
4350

4451
Usage:
4552
```sql
46-
ut.expect( a_actual {mulitple data-types} ).to_( be_empty() );
53+
declare
54+
l_cursor sys_refcursor;
55+
begin
56+
open l_cursor for select * from dual where 1 = 0;
57+
ut.expect( l_cursor ).to_( be_empty() );
58+
end;
4759
```
4860

4961
When used with anydata, it is only valid for collection data types.
@@ -53,39 +65,39 @@ Unary matcher that validates if the provided value is false.
5365

5466
Usage:
5567
```sql
56-
ut.expect( a_actual buulean ).to_( be_false() );
68+
exec ut.expect( ( 1 = 0 ) ).to_( be_false() );
5769
```
5870

5971
## be_greater_or_equal
6072
Allows to check if the actual value is greater or equal than the expected.
6173

6274
Usage:
6375
```sql
64-
ut.expect( a_actual {mulitple data-types} ).to_( be_greater_or_equal( a_expected {mulitple data-types}) );
76+
exec ut.expect( sysdate ).to_( be_greater_or_equal( sysdate - 1 ) );
6577
```
6678

6779
## be_greater_than
6880
Allows to check if the actual value is greater than the expected.
6981

7082
Usage:
7183
```sql
72-
ut.expect( a_actual {mulitple data-types} ).to_( be_greater_than( a_expected {mulitple data-types}) );
84+
exec ut.expect( 2 ).to_( be_greater_than( 1 ) );
7385
```
7486

7587
## be_less_or_equal
7688
Allows to check if the actual value is less or equal than the expected.
7789

7890
Usage:
7991
```sql
80-
ut.expect( a_actual {mulitple data-types} ).to_( be_less_or_equal( a_expected {mulitple data-types}) );
92+
exec ut.expect( 3 ).to_( be_less_or_equal( 3 ) );
8193
```
8294

8395
## be_less_than
8496
Allows to check if the actual value is less than the expected.
8597

8698
Usage:
8799
```sql
88-
ut.expect( a_actual {mulitple data-types} ).to_( be_less_than( a_expected {mulitple data-types}) );
100+
exec ut.expect( 3 ).to_( be_less_than( 2 ) );
89101
```
90102

91103

@@ -94,7 +106,8 @@ Validates that the actual value is like the expected expression.
94106

95107
Usage:
96108
```sql
97-
ut.expect( a_actual {mulitple data-types} ).to_( be_like( a_mask in varchar2, a_escape_char in varchar2 := null) );
109+
exec ut.expect( 'Lorem_impsum' ).to_( be_like( a_mask => '%rem\_%', a_escape_char => '\' ) );
110+
exec ut.expect( 'Lorem_impsum' ).to_( be_like( '%rem\_%', '\' ) );
98111
```
99112
100113
Parameters `a_mask` and `a_escape_char` represent a valid parameters of the [Oracle like function](https://docs.oracle.com/database/121/SQLRF/conditions007.htm#SQLRF52142)
@@ -105,15 +118,15 @@ Unary matcher that validates if the actual value is not null.
105118
106119
Usage:
107120
```sql
108-
ut.expect( a_actual {mulitple data-types} ).to_( be_not_null() );
121+
exec ut.expect( to_clob('ABC') ).to_( be_not_null() );
109122
```
110123
111124
## be_null
112125
Unary matcher that validates if the actual value is null.
113126
114127
Usage:
115128
```sql
116-
ut.expect( a_actual {mulitple data-types} ).to_( be_null() );
129+
exec ut.expect( cast(null as varchar2(100)) ).to_( be_null() );
117130
```
118131
119132
## be_true
@@ -122,7 +135,7 @@ Unary matcher that validates if the provided value is false.
122135
123136
Usage:
124137
```sql
125-
ut.expect( a_actual buulean ).to_( be_false() );
138+
exec ut.expect( ( 1 = 1 ) ).to_( be_true() );
126139
```
127140
128141
## equal
@@ -134,7 +147,13 @@ This matcher is designed to capture changes of data-type, so that if you expect
134147
135148
Usage:
136149
```sql
137-
ut.expect( a_actual {mulitple data-types} ).to_( equal( a_expected {mulitple data-types}, a_nulls_are_equal boolean := null) );
150+
declare
151+
x ref_cursor;
152+
y ref_cursor;
153+
begin
154+
ut.expect( 'a dog' ).to_( equal( 'a dog' ) );
155+
ut.expect( a_actual => y ).to_( equal( a_expected => x, a_nulls_are_equal => true ) );
156+
end;
138157
```
139158
The `a_nulls_are_equal` parameter decides on the behavior of `null=null` comparison (**this comparison by default is true!**)
140159
@@ -148,7 +167,7 @@ create or replace package demo_dept as
148167
-- %suite(demo)
149168
150169
--%test(demo_dept)
151-
procedure test_department
170+
procedure test_department;
152171
end;
153172
/
154173
@@ -171,7 +190,8 @@ Validates that the actual value is matching the expected regular expression.
171190
172191
Usage:
173192
```sql
174-
ut.expect( a_actual {mulitple data-types} ).to_( match( a_pattern in varchar2, a_modifiers in varchar2 := null) );
193+
exec ut.expect( a_actual => '123-456-ABcd' ).to_( match( a_pattern => '\d{3}-\d{3}-[a-z]', a_modifiers => 'i' ) );
194+
exec ut.expect( 'some value' ).to_( match( '^some.*' ) );
175195
```
176196
177197
Parameters `a_pattern` and `a_modifiers` represent a valid regexp pattern accepted by [Oracle regexp_like function](https://docs.oracle.com/database/121/SQLRF/conditions007.htm#SQLRF00501)
@@ -205,20 +225,22 @@ Expectations provide a very convenient way to check for a negative of the expect
205225
206226
Syntax of check for matcher evaluating to true:
207227
```sql
208-
ut.expect( a_actual {mulitple data-types} ).to_( {matcher} );
228+
exec ut.expect( a_actual {data-type} ).to_( {matcher} );
209229
```
210230
211231
Syntax of check for matcher evaluating to false:
212232
```sql
213-
ut.expect( a_actual {mulitple data-types} ).not_to( {matcher} );
233+
exec ut.expect( a_actual {data-type} ).not_to( {matcher} );
214234
```
215235
216236
If a matcher evaluated to NULL, then both `to_` and `not_to` will cause the expectation to report failure.
217237
218238
Example:
219239
```sql
240+
begin
220241
ut.expect( null ).to_( be_true() );
221242
ut.expect( null ).not_to( be_true() );
243+
end;
222244
```
223245
224246
Since NULL is neither true not it is not true, both expectations will report failure.

docs/userguide/install.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ The installation user/schema must have the following Oracle system permissions d
2525

2626
In addition it must be granted execute to the following system packages.
2727

28-
- DBMS_LOCK
28+
- DBMS_LOCK
29+
30+
The utPLSQL is using Oracle [DBMS_PROFILER tables](https://docs.oracle.com/cd/E18283_01/appdev.112/e16760/d_profil.htm#i999476). The tables will be created in the installation schema if they do not exist.
31+
The uninstall process however will not drop those tables, as they can potentially be shared and reused for profiling PLSQL code.
32+
It is up to DBA to maintain the storage of the profiler tables.
33+
2934

3035
# Installation Procedure
3136

docs/userguide/reporters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ Example of failure report details
7171

7272
#Teamcity reporter
7373

74-
[Teamcity](https://www.jetbrains.com/teamcity/) is a CI server by Jetbrains. The CI has it's own format of reporting that allows tracking of progress of a CI step/task as it executes.
75-
The format developed by Jetbrains is supported by utPLSQL with `ut_teamcity_reporter`.
74+
[Teamcity](https://www.jetbrains.com/teamcity/) is a CI server by Jetbrains. It supports XUnit reporting and additionally has it's own format of reporting that allows tracking of progress of a CI step/task as it executes.
75+
The TeamCity format developed by Jetbrains is supported by utPLSQL with `ut_teamcity_reporter`.
7676

7777
Invocation of tests with Teamcity reporter.
7878

docs/userguide/running-unit-tests.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The `run` API is designed to be called directly by developer, when using IDE/SQL
1010
The main benefit of using this API is it's simplicity.
1111
One-line call is enough to execute a set of tests form one or multiple schemes.
1212

13-
The **procedures** execute specified tests and produces outputs to DBMS_OUTPUT suing specified reporter
13+
The **procedures** execute specified tests and produces outputs to DBMS_OUTPUT using specified reporter
1414
The **functions** can only be used in SELECT statements. They execute specified tests and produce outputs as a pipelined data stream to be consumed by select satement.
1515

1616
## ut.run procedures
@@ -24,43 +24,49 @@ end;
2424
```
2525
Execute all tests in current schema (_HR_).
2626

27+
2728
```sql
2829
begin
2930
ut.run('HR');
3031
end;
3132
```
3233
Execute all tests in specified schema (_HR_).
3334

35+
36+
```sql
37+
begin
38+
ut.run('hr:com.my_org.my_project');
39+
end;
40+
```
41+
42+
Execute all tests from all packages that are on the _COM.MY_ORG.MY_PROJECT_ suitepath.
43+
Check the [annotations documentation](annotations.md) to find out about suitepaths and how they can be used to group test packages.
44+
45+
3446
```sql
3547
begin
3648
ut.run('hr.test_apply_bonus');
3749
end;
3850
```
3951
Execute all tests from package _HR.TEST_APPLY_BONUS_.
4052

53+
4154
```sql
4255
begin
4356
ut.run('hr.test_apply_bonus.bonus_cannot_be_negative');
4457
end;
4558
```
4659
Execute single test procedure _HR.TEST_APPLY_BONUS.BONUS_CANNOT_BE_NEGATIVE_.
4760

61+
4862
```sql
4963
begin
5064
ut.run(ut_varcahr2_list('hr.test_apply_bonus','cust'));
5165
end;
5266
```
5367
Execute all tests from package _HR.TEST_APPLY_BONUS_ and all tests from schema _CUST_.
54-
Using a list of things to execute allows you to execute a fine-grained set of tests.
55-
56-
```sql
57-
begin
58-
ut.run('hr:com.my_org.my_project');
59-
end;
60-
```
68+
Using a list of items to execute allows you to execute a fine-grained set of tests.
6169

62-
Execute all tests from all packages that are on the _COM.MY_ORG.MY_PROJECT_ suitepath.
63-
Check the [annotations documentation](annotations.md) to find out about suitepaths and how they can be used to group test packages.
6470

6571
**Note:**
6672
`ut_documentation_reporter` is default reporter for all API's defined for running unit tests.
@@ -75,6 +81,7 @@ end;
7581
```
7682
Execute all tests from package _HR.TEST_APPLY_BONUS_ and provide outputs to DBMS_OUTPUT using the XUnit reporter.
7783

84+
7885
For details on build-in reporters look at [reporters documentation](reporters.md).
7986

8087
## ut.run functions
@@ -91,15 +98,15 @@ select * from table(ut.run('hr.test_apply_bonus', ut_xunit_reporter()));
9198

9299
The `ut_runner` provides API for integrating utPLSQL with other products. Maven, Jenkins, SQL Develper, PL/SQL Developer, TOAD and others can leverage this API to call utPLSQL.
93100

94-
The main difference as compared to `ut.run` API is that the `ut_runner.run` does not provide outputs.
101+
The main difference as compared to `ut.run` API is that the `ut_runner.run` does not print outputs to the screen.
95102

96103
`ut_runner.run` accepts multiple reporters. Each reporter produces outputs into a separate output (uniquely identified by output_id).
97104
Outputs of multiple reporters can be consumed in parallel. This allows for live reporting of test execution progress with threads and several database sessions.
98105

99106
The concept is pretty simple.
100107

101-
- in main thread (session), define the reporters to be used. Each reporter has it's output_id and so you need to extract and store those output_id's.
108+
- in the main thread (session), define the reporters to be used. Each reporter has it's output_id and so you need to extract and store those output_id's.
102109
- as a separate thread, start the `ut_runner.run` and pass reporters with previously defined output_id's
103110
- for each reporter start a separate thread and read outputs from `ut_output_buffer.get_lines` table function by providing the output_id defined in the main thread.
104111

105-
112+
`ut_runner.run` is internally used by the [`ut_run.sql` script](ut_run-script.md) which is a utility for running tests with multiple reporters and provides parameters to save reporters results into individual files on the local file system.

0 commit comments

Comments
 (0)