Run utPLSQL tests
utPLSQL is a testing framework for Oracle databases. You can use utPLSQL to test packages, functions, procedures, triggers, views, and other objects that can be used in PL/SQL.
To use utPLSQL, install the framework into your Oracle database. See the installation instructions in the official utPLSQL documentation.
To get a quick overview of utPLSQL and examples, see Getting started with TDD and utPLSQL at utplsql.org.
To use utPLSQL objects in your tests, enable the utPLSQL schema in DataGrip.
Click the N of N link near the data source name. In the schema selection window, select the utPLSQL schema (for example,
UT3
).Press Enter.
In the Database Explorer (View | Tool Windows | Database Explorer) , right-click the Oracle data source and select Open Query Console.
Write the code of a function that you want to test. Consider the following example:
create or replace function sub_str( received_string varchar2, start_pos integer, end_pos integer ) return varchar2 is begin if start_pos = 0 then return substr( received_string, start_pos, end_pos - start_pos ); else return substr( received_string, start_pos, end_pos - start_pos + 1); end if; end; /
Click the Execute button (
) or press CtrlEnter.
In the Database Explorer (View | Tool Windows | Database Explorer) , right-click the Oracle data source and select Open Query Console.
In the editor, type code of a package that lists all your tests. Consider the following example:
create or replace package example_package as --%suite(Checks a substring in a string) --%test(Returns a substring when the start position is not zero) --%tags(basic) procedure start_not_zero; --%test(Returns a substring when the start position is zero) --%tags(with_zero) procedure start_zero; end; /
Click the Execute button (
) or press CtrlEnter.
In the Database Explorer (View | Tool Windows | Database Explorer) , right-click the Oracle data source and select Open Query Console.
In the editor, type code of test procedures. Consider the following example:
create or replace package body example_package as procedure start_not_zero is begin ut.expect( sub_str( '1234567', 2, 5 ) ).to_equal('2345'); end; procedure start_zero is begin ut.expect( sub_str( '1234567', 0, 5 ) ).to_equal('12345'); end; end; /
Click the Execute button (
) or press CtrlEnter.
Open the Run/Debug Configuration dialog in one of the following ways:
Select Run | Edit Configurations from the main menu.
With the Navigation bar visible (View | Appearance | Navigation Bar), choose Edit Configurations from the run/debug configuration selector.
Press AltShiftF10 and then press 00.
In the Run/Debug Configurations dialog, click the Add New Configuration icon (
) and select utPLSQL Test.
Data source: a name of a data source. utPLSQL supports Oracle.
Paths: a qualified path to the testing package (for example,
GUEST.EXAMPLE_PACKAGE
).Tags: tags of tests that you want to run. Use semicolon (
;
) as separator (for example,basic;with_zero
).
For more information about settings of the utPLSQL Test configuration type, refer to utPLSQL Test.
You can either run the configuration right away or save the configuration to run it later.
To save the run configuration for later, click OK.
To run the configuration right away, click Run.
![https://resources.jetbrains.com/help/img/idea/2024.3/db_run_utplsql_tests.png](https://resources.jetbrains.com/help/img/idea/2024.3/db_run_utplsql_tests.png)
In the Database Explorer (View | Tool Windows | Database Explorer) , double-click the test.
In the editor, click the Run icon
in the gutter and select Run <procedure_name>.
In the Run tool window, click the Rerun failed tests button
Thanks for your feedback!