[ Home | Getting Started | Build Test Packages | Examples | User Guide | Release Notes | Document Map ]
< Previous Section: utPLSQL Package | Next Section: utResult Package >
This package contains the following functions and procedures:
To make it as easy as possible for you to run your tests, utPLSQL stores various pieces of configuration data in the ut_config table. This data is stored by schema name and is automatically loaded into utPLSQL the first time you use this utility in your session. This configuration information is also automatically updated whenever you call utPLSQL.test -- or any of the utPLSQL programs specifically designed to change the configuration settings.
You can at any time view the utPLSQL configuration for the currently-connected schema or for another schema (there is not at this point any schema-level security; all utPLSQL users can view the configurations of all other users).
The data that is currently maintained for a utPLSQL user are:
Test package directory - the location of the test package code you want to run. You must specify a directory in order to allow utPLSQL to automatically compile your test packages before each test run.
Unit test prefix - the prefix used for test package names and the program names within the package. If you do not specify a prefix, the default of "ut_" is automatically applied.
Unit test registration mode - This setting determines whether utPLSQL will automatically identify the unit tests to be run (strongly recommended) or if you have chosen to manually register your unit tests in the test package setup procedure.
Auto-compilation of test packages - By default, utPLSQL will recompile your test package before execution. You can turn off this feature and manually recompile only when you desire (a fine idea if your test package has gotten very large!).
By default, the configuration stored for the currently-connected user will be used. However, it is possible to use configurations stored against other usernames. To show whose configuration is currently being used the following function is used:
FUNCTION utConfig.tester RETURN VARCHAR2;
This returns the configuration that will be used whenever a username is not specified. To set this, the following procedure is used:
PROCEDURE utConfig.settester (username_in IN VARCHAR2 := USER);
Call the utconfig.showconfig procedure to view the configuration for a specified schema. The header is:
PROCEDURE utConfig.showconfig (username_in IN VARCHAR2 := NULL);
If you do not specify a schema, then the currently used configuration is returned. Here is an example of output from this procedure:
SQL> exec utconfig.showconfig ============================================================= utPLSQL Configuration for SCOTT Directory: /apps/utplsql/code Autcompile? Y Manual test registration? N Prefix = test_ =============================================================
And here is an example of calling showConfig for a different schema:
SQL> exec utconfig.showconfig ('COMP') ============================================================= utPLSQL Configuration for COMP Directory: M:\shared_apps\utplsql\comp Autcompile? N Manual test registration? N Prefix = ut_ =============================================================
You might want to put a call to showConfig in your SQL*Plus login file so that you are reminded on startup as to what the current settings are. Here is such a script (to be found in Examples\login_sample.sql):
exec utconfig.setdir ('e:\openoracle\utplsql\utinstall\examples') SET SERVEROUTPUT ON SIZE 1000000 FORMAT WRAPPED exec utconfig.showconfig
If you want utPLSQL to compile your test package, you must tell it the directory in which your code is found. You can do this either when you define your test suite and packages within the suite, or you can call the utConfig.setdir procedure to set the directory for your current session.
Note: as of v1.5.1, the value you pass in any of these programs is saved in the configuration table and will be used in the future -- until you change it by passing a different value.
The header for this procedure is:
PROCEDURE utConfig.setdir (dir_in IN VARCHAR2, username_in IN VARCHAR2 := NULL);
where dir_in is the directory and username_in is the name of the schema to which this directory applies (NULL means the currently used configuration is set), as in:
SQL> exec utconfig.setdir ('e:\demo\utplsql');
or, with the specification of a non-current schema:
SQL> exec utconfig.setdir ('e:\demo\utplsql', 'ANALYSIS');
Note that this directory must be accessible through UTL_FILE.
You might consider putting the the call to utConfig.setdir into your login.sql so that it is run automatically, each time your start up SQL*Plus -- if you are always working from the same directory.
You can obtain the current directory with a call to utConfig.dir:
FUNCTION utConfig.dir (username_in IN VARCHAR2 := NULL) RETURN VARCHAR2;
The unit test prefix is very important in utPLSQL; the utility uses the prefix to associate source code to be tested with the test package. The prefix also allows utPLSQL to automatically identify the programs within a test package that are to be executed as unit tests.
The default prefix in utPLSQL is "ut_", but you can override this when you call utPLSQL.test or by calling the utConfig.setprefix procedure:
PROCEDURE utConfig.setPrefix ( prefix_in IN VARCHAR2, username_in IN VARCHAR2 := NULL)
where prefix_in is the prefix and username_in is the name of the schema to which this prefix applies (NULL means the currently used configuration is set), as in:
SQL> exec utconfig.setPrefix ('tst#');
or, with the specification of a non-current schema:
SQL> exec utconfig.setPrefix ('t_', 'ANALYSIS');
You can obtain the current prefix with a call to utConfig.prefix:
FUNCTION utConfig.prefix (username_in IN VARCHAR2 := NULL) RETURN VARCHAR2;
uPLSQL currently does not support the use of a suffix, or combination of suffix and prefix, to identify test packages and unit test procedures.
As of utPLSQL v1.5.1, you no longer have to register your unit test procedures in the setup procedure of your test package. Instead, utPLSQL will scan the data dictionary (via theALL_ARGUMENTS view) for the names of all the unit test procedures you have defined, and then run them. utPLSQL identifies these programs by looking for all programs whose names start with the specified prefix.
If you so choose, you can request that utPLSQL turn off automatic detection of unit test procedures and only run those programs listed in the setup procedure. To do this, you call the utConfig.registerTest procedure:
PROCEDURE utConfig.registerTest ( onoff_in IN BOOLEAN, username_in IN VARCHAR2 := NULL );
as in:
SQL> exec utConfig.registerTest (TRUE)
Note: if you are using automatic unit test detection, any calls to utPLSQL.addtest in the setup procedure will be ignored.
You can return the current registration mode using the following function:
FUNCTION registeringtest (username_in IN VARCHAR2 := NULL) RETURN BOOLEAN;
This returns TRUE if the registration mode has been set to manual and FALSE otherwise.
The default settings for utPLSQL is to re-compile your base package before each unit test. This guarantees that any recent changes will be tested. It also saves you the step of doing an explicit compile.
In order to perform automatic compilation:
In general (and the default), you should allow your test package to be recompiled with each execution. You might want to avoid recompilation if:
If you are working with products like SQL*Navigator, you may be always editing from code stored in the database. In this case, you will never want to have utPLSQL recompile your code for you - it will already be compiled and you do not need to hassle with UTL_FILE.
You can avoid auto-recompilation in two ways:
1. Pass a value of FALSE for the recompile_in argument to utPLSQL.test or utPLSQL.testsuite. Here is an example:
BEGIN -- Define a test suite for PL/Vision utsuite.add ('PLVision'); -- Add two packages for testing utsuite.addpkg ( 'PLVision', 'PLVstr', dir_in => 'e:\utplsql'); utsuite.addpkg ( 'PLVision', 'PLVdate', dir_in => 'e:\utplsql'); -- Run the test suite utplsql.testsuite ( 'PLVision', recompile_in => FALSE); END; /
If you know that you will never want to recompilation, however, you can set the default behavior at the schema level by calling the autocompile procedure
PROCEDURE utConfig.autocompile ( onoff_in IN BOOLEAN, username_in IN VARCHAR2 := NULL );
So I can make the following call to turn off autocompilation for the SCOTT schema:
SQL> exec utconfig.autocompile (FALSE, 'SCOTT')
This program updates the ut_config table with your information and then commits the setting.
You can determine the current setting for auto-compilation at any time by calling the following function:
FUNCTION utConfig.autocompiling (username_in IN VARCHAR2 := NULL) RETURN BOOLEAN;
Note: When you set the schema-level recompilation value to FALSE, that will override anything you pass in a call to utPLSQL.test or utPLSQL.testsuite.
You can set the delimiter to be used in V2 procedure names using the following procedure:
PROCEDURE setdelimiter ( delimiter_in IN VARCHAR2, username_in IN VARCHAR2 := NULL );
while the current delimiter can be obtained by the function:
FUNCTION delimiter (username_in IN VARCHAR2 := NULL) RETURN VARCHAR2;
By default, the results of all the tests are shown. This includes both successful and unsuccessful results. The following procedure allows you to limit the tests shown to only those that have failed:
PROCEDURE showfailuresonly ( onoff_in IN BOOLEAN, username_in IN VARCHAR2 := NULL );
the current setting can be obtained by the function:
FUNCTION showingfailuresonly (username_in IN VARCHAR2 := NULL) RETURN BOOLEAN;
By default, all results are sent to the screen via DBMS_OUTPUT. However, it is possible to use other output reporters as described in more detail on this page. The following procedure allows you to set which output reporter should be used by default:
PROCEDURE setreporter ( reporter_in IN VARCHAR2 ,username_in IN VARCHAR2 := NULL );
as usual, the current setting can be obtain by the following function:
FUNCTION getreporter (username_in IN VARCHAR2 := NULL) RETURN VARCHAR2;
< Previous Section: utPLSQL Package | Next Section: utResult Package >
Copyright © 2000-2005, 2014-2016 Steven Feuerstein, Chris Rimmer, Patrick Barel and the utPLSQL Project. All rights reserved