Chat now with support
Chat with Support

Toad for Oracle 15.0 - Getting Started Guide

Welcome to Toad Toad Resources Required Privileges Create and Manage Database Connections Editor Basics Schema Browser Basics Data Grid Basics Work with Data Work with Database Objects Work with Code
Write Statements and Scripts Work with the Query Builder Execute Statements and Scripts Save Statements (SQL Recall) Work with PL/SQL Objects Debug Analyze Code Optimize SQL
Customize your Toad Environment Use Other Quest Software Products with Toad

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:

  1. Use the Create Unit Test window
  2. Execute or debug a PL/SQL subprogram and create new tests using the inputs provided and outputs produced
  3. 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

  1. 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.

  2. 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:

    1. Owner. Select a schema for the test suite.
    2. Name. If creating a new test suite, enter a suite name. Otherwise, select an existing one.
    3. 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.
    4. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Click Add Unit Test to add a unit test to the suite. A suite must contain at least one unit test.
  7. Test Information. Enter test information:

    1. Enter a test name. In utPLSQL, a unit test is a PL/SQL procedure (subprogram).
    2. Enter a description (optional) to display in reports and the Unit Test Manager.
  8. Tested Object. Select a PL/SQL object to test.
    1. Owner. Select the schema containing the PL/SQL object.
    2. Name. Select the PL/SQL object.
  9. Tested Value. Specify a variable to test, an expected value, and a comparison operation. You can enter your inputs later in Editor.
    1. Expect. Enter or select a variable to test against an expected value.
    2. To. Select a comparison operation.
    3. Value. Enter the expected value, variable, or expression. This value will be compared to the result.
  10. 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.
  11. 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.
  12. Click Add Unit Test again to add an another test. Add as many tests to the suite as necessary.
  13. To remove a test from the suite, click X in the upper-right corner of the dialog used to define that test.
  14. 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

 

Related Documents

The document was helpful.

Select Rating

I easily found the information I needed.

Select Rating