You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
utPLSQL is a Unit Testing framework for Oracle PL/SQL.
6
6
The framework follows industry standards and best patterns of modern Unit Testing frameworks like [JUnit](http://junit.org/junit4/) and [RSpec](http://rspec.info/)
7
-
8
-
- User Guide
9
-
- [Installation](userguide/install.md)
10
-
- [Getting Started](userguide/getting-started.md)
11
-
- [Annotations](userguide/annotations.md)
12
-
- [Expectations](userguide/expectations.md)
13
-
- [Advanced data comparison](userguide/advanced_data_comparison.md)
14
-
- [Running unit tests](userguide/running-unit-tests.md)
15
-
- [Querying for test suites](userguide/querying_suites.md)
16
-
- [Testing best practices](userguide/best-practices.md)
-[Version 2 to Version 3 Comparison](compare_version2_to_3.md)
29
-
30
-
# Demo project
7
+
8
+
## Demo project
31
9
32
10
Have a look at our [demo project](https://github.com/utPLSQL/utPLSQL-demo-project/).
33
11
34
12
It uses [Travis CI](https://travis-ci.org/utPLSQL/utPLSQL-demo-project) to build on every commit, runs all tests, publishes test results and code coverage to [SonarCloud](https://sonarcloud.io/project/overview?id=utPLSQL:utPLSQL-demo-project).
35
13
36
-
# Three steps
14
+
##Three steps
37
15
38
16
With just three simple steps you can define and run your unit tests for PLSQL code.
39
17
@@ -48,7 +26,7 @@ Here is how you can simply create tested code, unit tests and execute the tests
48
26
Check out the sections on [annotations](userguide/annotations.md) and [expectations](userguide/expectations.md) to see how to define your tests.
49
27
50
28
51
-
# Command line
29
+
##Command line
52
30
53
31
You can use the utPLSQL command line client [utPLSQL-cli](https://github.com/utPLSQL/utPLSQL-cli) to run tests without the need for Oracle Client or any IDE like SQLDeveloper/TOAD etc.
54
32
@@ -60,7 +38,7 @@ Amongst many benefits they provide ability to:
60
38
Download the [latest client](https://github.com/utPLSQL/utPLSQL-cli/releases/latest) and you are good to go.
61
39
See [project readme](https://github.com/utPLSQL/utPLSQL-cli/blob/develop/README.md) for details.
62
40
63
-
# Coverage
41
+
##Coverage
64
42
65
43
If you want to have code coverage gathered on your code , it's best to use `ut_run` to execute your tests with multiple reporters and have both test execution report as well as coverage report saved to a file.
Annotations are used to configure tests and suites in a declarative way similar to modern OOP languages. This way, test configuration is stored along with the test logic inside the test package.
6
4
No additional configuration files or tables are needed for test cases. The annotation names are based on popular testing frameworks such as JUnit.
7
5
The framework runner searches for all the suitable annotated packages, automatically configures suites, forms the suite hierarchy, executes it and reports results in specified formats.
@@ -38,7 +36,7 @@ There **can not** be any empty lines or comments between annotation line and pro
utPLSQL comes with a built-in coverage reporting engine. The code coverage reporting uses package DBMS_PROFILER (and DBMS_PLSQL_CODE_COVERAGE on Oracle database version 12.2 and above) provided with Oracle database.
5
4
Code coverage is gathered for the following source types:
5
+
6
6
* package bodies
7
7
* type bodies
8
8
* triggers
@@ -15,6 +15,7 @@ Code coverage is gathered for the following source types:
15
15
16
16
To obtain information about code coverage for unit tests, run utPLSQL with one of built-in code coverage reporters.
17
17
The following code coverage reporters are supplied with utPLSQL:
18
+
18
19
*`ut_coverage_html_reporter` - generates a HTML coverage report providing summary and detailed information on code coverage. The HTML reporter is based on the open-source [simplecov-html](https://github.com/colszowka/simplecov-html) reporter for Ruby. It includes source code of the code that was covered (if the code is accessible for test user)
19
20
*`ut_coveralls_reporter` - generates a [Coveralls compatible JSON](https://coveralls.zendesk.com/hc/en-us/articles/201774865-API-Introduction) coverage report providing detailed information on code coverage with line numbers. This coverage report is designed to be consumed by cloud services like [Coveralls](https://coveralls.io)
20
21
*`ut_coverage_sonar_reporter` - generates a [Sonar Compatible XML](https://docs.sonarqube.org/latest/analysis/generic-test/) coverage report providing detailed information on code coverage with line numbers. This coverage report is designed to be consumed by services like [SonarQube](https://www.sonarqube.org/) and [SonarCloud](https://about.sonarcloud.io/)
@@ -23,6 +24,7 @@ The following code coverage reporters are supplied with utPLSQL:
23
24
## Security model
24
25
utPLSQL code coverage uses DBMS_PROFILER to gather information about the execution of code under test and therefore follows the [DBMS_PROFILER's Security Model](https://docs.oracle.com/database/121/ARPLS/d_profil.htm#ARPLS67465).
25
26
In order to be able to gather coverage information, the user executing unit tests needs to be either:
27
+
26
28
* The owner of the code that is being tested
27
29
* Have the following privileges to be able to gather coverage on code owned by other users:
28
30
*`create any procedure` system privilege
@@ -144,6 +146,7 @@ You may specify both _include_ and _exclude_ options to gain more control over w
144
146
145
147
**Important notes**
146
148
The order of priority is for evaluation of include/exclude filter parameters is as follows.
149
+
147
150
- if `a_source_file_mappings` is defined then all include/exclude parameters are ignored (see section below for usage of `a_source_file_mappings` parameter )
148
151
- else if `a_include_schema_expr` or `a_include_object_expr` parameter is specified then parameters `a_coverage_schemes` and `a_include_objects` are ignored
149
152
- else if `a_include_objects` is specified then the coverage is gathered only on specified database objects.
@@ -300,6 +303,7 @@ They are abstracted from database, schema names, packages, procedures and functi
300
303
To be able to effectively use reporters dedicated for those tools, utPLSQL provides functionality for mapping database object names to project files.
301
304
302
305
There are a few significant differences when running coverage on project files compared to running coverage on schema(s).
306
+
303
307
- Coverage is only reported on objects that were successfully mapped to project files.
304
308
- Project files (database objects) that were not executed at all are not reported as fully uncovered. It is up to the consumer (Sonar/Coveralls) to determine if project file should be considered as 0% coverage or just ignored.
305
309
@@ -335,6 +339,7 @@ C:
335
339
```
336
340
337
341
By default, utPLSQL will convert file paths into database objects using the following regular expression `/(((\w|[$#])+)\.)?((\w|[$#])+)\.(\w{3})$`
342
+
338
343
- object owner (if it is present) is identified by the expression in the second set of brackets
339
344
- object name is identified by the expression in the fourth set of brackets
340
345
- object type is identified by the expression in the sixth set of brackets
The utPLSQL is responsible for handling exceptions wherever they occur in the test run. utPLSQL is trapping most of the exceptions so that the test execution is not affected by individual tests or test packages throwing an exception.
6
4
The framework provides a full stacktrace for every exception that was thrown. The stacktrace is clean and does not include any utPLSQL library calls in it.
7
5
To achieve rerunability, the package state invalidation exceptions (ORA-04068, ORA-04061) are not handled and test execution will be interrupted if such exceptions are encountered. This is because of how Oracle behaves on those exceptions.
8
6
9
7
Test execution can fail for different reasons. The failures on different exceptions are handled as follows:
8
+
10
9
* A test package without body - each `--%test` is reported as failed with exception, nothing is executed
11
10
* A test package with _invalid body_ - each `--%test` is reported as failed with exception, nothing is executed
12
11
* A test package with _invalid spec_ - package is not considered a valid unit test package and is excluded from execution. When trying to run a test package with invalid spec explicitly, exception is raised. Only valid specifications are parsed for annotations
Since NULL is neither *true* nor *false*, both expectations will report failure.
314
317
315
-
# Supported data types
318
+
##Supported data types
316
319
317
320
The matrix below illustrates the data types supported by different matchers.
318
321
@@ -336,7 +339,7 @@ The matrix below illustrates the data types supported by different matchers.
336
339
|**be_within().of_()**|||| X | X | X | X | X ||||||||
337
340
|**be_within_pct().of_()**||||| X |||||||||||
338
341
339
-
# Expecting exceptions
342
+
##Expecting exceptions
340
343
341
344
Testing is not limited to checking for happy-path scenarios. When writing tests, you often want to validate that in specific scenarios, an exception is thrown.
342
345
@@ -385,7 +388,7 @@ Finished in .009229 seconds
385
388
For more details see documentation of the [`--%throws` annotation.](annotations.md#throws-annotation)
386
389
387
390
388
-
# Matchers
391
+
##Matchers
389
392
390
393
You can choose different matchers to validate that your PL/SQL code is working as expected.
391
394
@@ -1747,7 +1750,7 @@ FAILURE
1747
1750
at "anonymous block", line 32
1748
1751
```
1749
1752
1750
-
# Comparing Json objects
1753
+
## Comparing Json objects
1751
1754
1752
1755
utPLSQL is capable of comparing json data-types of `json_element_t` **on Oracle 12.2 and above**, and also `json` **on Oracle 21 and above**
0 commit comments