Create Unit Tests
utPLSQL test suites are Oracle packages using annotations similar to JUnit. Annotations are comments structured so that the framework can identify packages that are suites and which subprograms within are tests. There are several methods you can use to create unit tests:
- Use the Create Unit Test window
- Execute or debug a PL/SQL subprogram and create new tests using the inputs provided and outputs produced
- Write test suite and unit test code from the ground up in the Editor. Visit https://utplsql.org/resources/ for documentation, how-to guides, and best practices.
Create Unit Test Window
Use the Create Unit Test window to create test suites and unit tests. This window allows you to create a test suite and the test code for one or more unit tests. You can then send the test code to Editor for further work.
After finishing a unit test in Editor, you can run the test from Editor or from Unit Test Manager.
To create unit test code
Select Unit Testing | Create Unit Test to open the Create Unit Test window or right-click a test in Unit Test Manager and select Add New Test to Suite.
Test Suite. Create a new test suite or select an existing one. In utPLSQL, a test suite is required. Suite information is used by utPLSQL to identify, configure, and run unit tests. A suite can contain one or more unit tests.
Enter suite information:
- Owner. Select a schema for the test suite.
- Name. If creating a new test suite, enter a suite name. Otherwise, select an existing one.
- Suite path. (New suite) Select an existing path or enter a new one. Suite path allows you to logically group related test suites. The utPLSQL annotation %suitepath is added to the suite code in the Preview pane.
- Description. (New suite) A description is optional. It is displayed in reports and in the Unit Test Manager. The utPLSQL annotation %displayname is added to the suite code in the Preview pane.
- Preview pane. Notice how suite and test code is automatically modified in the body and spec preview panes . You cannot directly edit code using the Preview pane. You can edit your test code directly after you send it to Editor.
- Click Show more options to select the suite subprogram stubs you would like to create. For a description of each subprogram, see http://utplsql.org/utPLSQL/v3.1.9/userguide/annotations.html.
- To enable a suite, click Show more options and check the Enable suite check box. The utPLSQL annotation %disabled is removed from the suite code.
- Click Add Unit Test to add a unit test to the suite. A suite must contain at least one unit test.
Test Information. Enter test information:
- Enter a test name. In utPLSQL, a unit test is a PL/SQL procedure (subprogram).
- Enter a description (optional) to display in reports and the Unit Test Manager.
- Tested Object. Select a PL/SQL object to test.
- Owner. Select the schema containing the PL/SQL object.
- Name. Select the PL/SQL object.
- Tested Value. Specify a variable to test, an expected value, and a comparison operation. You can enter your inputs later in Editor.
- Expect. Enter or select a variable to test against an expected value.
- To. Select a comparison operation.
- Value. Enter the expected value, variable, or expression. This value will be compared to the result.
- Click Show more options to select the test subprogram stubs you would like to create. For a description of each subprogram, see http://utplsql.org/utPLSQL/v3.1.9/userguide/annotations.html.
- To disable a test, click Show more options and clear the Enable test check box. The utPLSQL annotation %disabled is added to the test code.
- Click Add Unit Test again to add an another test. Add as many tests to the suite as necessary.
- To remove a test from the suite, click X in the upper-right corner of the dialog used to define that test.
When you are finished adding tests, click Send to Editor to generate the test code and send it to Editor. In Editor, you can modify code, including setup and teardown subprograms, add inputs, and finalize your unit tests.
Note: utPLSQL test suites are Oracle packages. You must compile the spec first and then the body as you would with any other new package.
You can also run your unit tests from Editor.
Create Unit Test From Execution Results
After executing or debugging PL/SQL subprograms, you can create new tests using the inputs you've provided and the outputs produced. Create and Run Unit Tests From Execution Results