Show Menu
Cheatography

utPLSQL 3.1.10 Cheat Sheet by

Commands and Features of utPLSQL 3.1.10 http://utplsql.org

Define Test Suites with Annota­tions

Annotations are single­-line comments and belong in the package header. Put a newline between package and procedure annota­tions.

Package Annota­tions

--%s­uit­e­(de­scr­iption)
Package is a test-suite (opti­onal descri­ption). Manda­tory
--%sui­tep­ath­(or­g.u­tplsql)
Groups suites in hierar­chical namespaces
--%rol­­lb­a­c­k(a­uto­|ma­­nual)
Automatic (defa­ult) / manual transa­ction control
--%context(description)
--%endcontext
Starts­/ends sub-suite in suite. Can be nested.
--%dis­abled
Tests of suite/­context won't be executed
--%bef­­or­e­a­ll­­(pr­­oc­edure [, ...])
--%afterall...
Proced­ure(s) to run before­/after all tests in the suite/­context
--%bef­oreeach­(pr­ocedure [, ...])
--%aftereach...
Proced­ure(s) to run before­/after each test in the suite/­context
--%tag­s(m­yTag[, ...)
Label a test/c­ont­ext­/suite

Procedure Annota­tions

--%tes­t(d­esc­rip­tion)
Procedure is a test (with optional descri­ption)
--%dis­abled
Test won't be executed
--%thr­­ow­s­(­ex­­ception [, ...])
Test expects except­ion(s) to be thrown
--%bef­­or­e­all, --%afterall
--%beforeeach, --%aft­ereach
Procedure to run before­/after all/each tests in the suite/­context
--%beforetest(p­roc­edure [, ...])
--%aftertest(procedure [, ...])
Proced­ure(s) to be run before­/after annotated test
--%tag­s(m­yTag[, ...)
Label test

Run Tests

exec ut.run();
Run all tests to the default reporter (DBMS_­OUTPUT)
select * from table( ut.run­());
Run all tests and display output as result set
Consider using utplsql-cli to easily run tests

Run specific tests

ut.ru­n('­my_­sui­te_­pckg')
Run only the specified suite by name (current schema)
ut.ru­n('­HR')
Run all tests in specific schema
ut.run('my_suite.test1,
  my_suite.test2')
Run list of items
ut.run(':my.suite.path')
Run specific suite path

Run Parameters

a_force_manual_rollback
True/F­alse. Run specified test and don't rollback changes (leaves open transa­ction)
a_ran­dom­_te­st_­order
True/F­alse. Run tests in random order
a_col­or_­con­sole
True/F­alse. Color-code output (for Windows see ANSICON)
a_cli­e­n­t_­­cha­­ra­c­t­er_set
a_tags
Run tests with any specified tags.
Use a_tag­s=>­'-t­ag1' to exclude a tag

Reporting: Run altern­ative Reporter

exec ut.run­(ut­_ju­nit­_re­por­ter­());

Reporters

UT_DOCUMENTATION_REPORTER
Textual pretty­-print of test results. Default
UT_CO­VER­AGE­_HT­ML_­REP­ORTER
HTML Coverage Report, includes SourceCode
UT_JU­NIT­_RE­PORTER
Test results conforming to JUnit 4 and above
UT_RE­ALT­IME­_RE­PORTER
Test results and additional inform­ation as XML. Allows to show progress inform­ation
UT_SO­NAR­_TE­ST_­REP­ORTER
JSON Test results designed for SonarQube
See full list of built-in reporters. See docume­ntation for coverage and reporters.
 

Expect­ation Syntax

Base expectation
ut.ex­pect( actua­­l_­v­alue ).to_( matc­­her );
Negated expect­ation
ut.ex­pect( actua­­l_­v­alue ).not_to_( matc­­her );
Shortcut syntax (recommended)
ut.ex­pect( actua­­l_­v­alue ).to_matcher;
ut.expect( actua­­l_­v­alue ).not_­­to­_­­m­­atc­­he­r;

Provide additional expect­ation descri­ption

ut.ex­pect(1, 'Add­­it­ional text'­­).t­­o_­­equ­­al­(3);

Simple Matchers

ut.ex­pec­t(1­=1).to­_­be_­tru­e();
ut.ex­pect(1 is null).t­o_­b­e_f­als­e();
ut.ex­pec­t(n­ull­).t­o_­be­_nu­ll­();
ut.ex­pec­t(t­o_c­lob­('A­BC'­)).t­o_­b­e_n­ot_­nul­l();
ut.ex­­pect( 3 ).to_­b­­e_b­­et­ween( 1, 3 );
ut.ex­­pect( 3 ).to_­b­­e_g­­re­a­t­er­­_or­­_e­qual( 2 );
ut.ex­­pect( 2 ).to_­b­­e_g­­re­a­t­er­­_th­an( 1 );
ut.ex­­pect( 3 ).to_­b­­e_l­­es­s­_­or­­_eq­ual( 3 );
ut.ex­­pect( 3 ).to_­b­­e_l­­es­s­_­than( 4 );

Equality Matchers

ut.ex­­pect( 'a dog' ).to_­eq­ual­('a dog',
  a_null­s_a­re_­equal => false );

a_nulls_are_equal is true by default
equal on objects
ut.expect(anydata.convertObject(l_expect))
  .to_equal(anydata.convertObject(l_actual));
equal on collections
ut.expect(anydata.convertCollection(l_expect))
  .to_equal(anydata.convertCollection(l_actual));
It's not possible to compare rowtypes and records directly. You have to wrap them in a table of record , select from them and use cursor comparsion

Advanced Matchers

be_like
ut.ex­pect( 'Lorem­­_i­m­psum' )
  .to_b­e_like( '%re%su' );

be_like
with escape
ut.ex­­pect( 'Lorem­­_i­m­psum' )
  .to_be_like(
    a_mask => '%rem\_%',
    a_esca­pe_char => '\' );

see Oracle like operator
match
ut.ex­pec­t('some value')
  .to_m­atch('^some.*');
match
with options
ut.ex­­pect( '123-4­­56­-­ABcd' )
  .to_match(
    a_pattern=>'\d{3}-\d{3}-[a-z]',
    a_modifiers=>'i');

See regexp_like function

Cursor Comparison

Basic example
open l_expected for select * from all_objects;
open l_actual for select * from all_objects;
ut.expect(l_actual)
  .to_equal(l_expected)
  .join_by('COLUMN_NAME')
  .exclude(ut_varchar2_list('ID','SOMECOLUMN'))
Special Matchers
ut.expect(l_actual).to_have_count(5);
ut.expect(l_actual).to_be_empty();

Helpers

Type: List of strings
ut_varchar2_list('String 1', 'String 2', ...)
Type: List of reporters
ut_reporters(ut_documentation_reporter(), ut_jun­it_­rep­ort­er())
Select all tests
select * from table(
  ut_runner.get_suites_info(USER, 'PACKAGE_NAME'))
  where item_type = 'UT_TE­ST';
                       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          utPLSQL v3.1.2 Cheat Sheet
          Selenium WebDriver Cheat Sheet Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet