Show Menu
Cheatography

utPLSQL v3.1.2 Cheat Sheet by

utPLSQL v3.1.2

Common annota­tions

--%dis­abled
Suite / context / test will not execute
--%rol­lba­ck(auto / ma­nual)
--%dis­pla­yname( descri­ption )
Descri­ption of context / test / suite

Procedure annota­tions

--%tes­t(d­esc­rip­tion)
Procedure is a test (with descri­ption)
--%bef­ore­tes­t(p­roc­edure [, ...])
Proced­ure(s) to run
before annotated test
--%aft­ert­est­(pr­ocedure [, ...])
Proced­ure(s) to run
after annotated test
--%bef­oreall
Procedure to run
before first test in suite/­context
--%aft­erall
Procedure to run
after last test in suite/­context
--%bef­oreeach
Procedure to run
before each test in suite/­context
--%aft­ereach
Procedure to run
after each test in suite/­context
--%thr­ows­(ex­ception [, ...])
Test expects
exception(s) to be thrown

Package annota­tions

--%sui­te(­des­cri­ption)
Package is a test suite
(with descri­ption)
--%sui­tep­ath­(co­m.a­cme.bomb)
Similar to classpath (Java)
Group suites in namespaces
--%con­tex­t(name)
Starts sub-suite in a suite
--%end­context
Ends sub-suite in a suite
--%bef­ore­all­(pr­ocedure [, ...])
Proced­ure(s) to run
before all tests in suite/­context
--%aft­era­ll(­pro­cedure [, ...])
Proced­ure(s) to run
after all tests in suite/­context
--%bef­ore­eac­h(p­roc­edure [, ...])
Proced­ure(s) to run
before each tests in suite/­context
--%aft­ere­ach­(pr­ocedure [, ...])
Proced­ure(s) to run
after each tests in suite/­context
Annota­tions are sinlgl­e-line comments starting with a % sign.
Needed in package specif­ication only (docum­ent­ation)

Equality matcher

equal
ut.expect( 'a dog' ).to_equal(
  'a dog' , a_null­s_a­re_­equal => false );

a_nulls_are_equal is true by default
equal with cursors
open l_expected for select * from all_ob­jects;

open l_actual for select * from all_ob­jects;

ut.expect( l_expected )
  .to_equal( l_actual )
  .exclude( 'owner' )
  .join_by( 'name' );
equal on objects
ut.expect(
  anydata.convertObject(l_expected) )
.to_equal(
  anydata.convertObject(l_actual) );
equal on collec­tions
ut.expect(
  anydata.convertCollection(l_expected) )
.to_equal(
  anydata.convertCollection(l_actual) );

Expect­ation syntax

Base expect­ation
ut.expect( actual­_value ).to_( matcher );
Negated expect­ation
ut.expect( actual­_value ).not_to( matcher );
Shortcuts syntax
ut.expect( actual­_value ).to_matcher;

ut.expect( actual­_value ).not_to_matcher;
 

Executing tests

exec ut.run();
All tests in my current schema
alter session set curren­t_s­che­ma=­'HR';

exec ut.run();
All tests in current schema after it was changed to HR
exec ut.run­('HR');
All tests in specific schema
exec ut.run­('t­est­_be­twn­str');
All tests in package of current schema
exec ut.run­('h­r.t­est­_be­twn­str.bi­g_e­nd_­pos­iti­on');
Specific test only
exec ut.run(
    'hr.test_award_bonus, hr.tes­t_b­etw­nst­r.b­ig_­end­_po­sit­ion');
Run several items
exec ut.run­(':­com.my­_or­g.m­y_p­roj­ect');
Run using suitepath
select * from table(­ut.r­un());
All tests as a select statement

Non-eq­uality matchers

be_like
ut.expect( 'Lorem­_im­psum' ).to_be_like(
  a_mask => '%rem\_%', a_esca­pe_char => '\' );

ut.expect( 'Lorem­_im­psum' ).to_b­e_like( '%re%su' );

a_mask, a_esca­pe_char -> see Oracle like operator
match
ut.expect( '123-4­56-­ABcd' ).to_match(
  a_pattern=>'\d{3}-\d{3}-[a-z]', a_modifiers=>'i'
);

ut.expect( 'some value' ).to_m­atch( '^some.*' );

a_pattern, a_modi­fiers -> see regexp­_like function
be_between
ut.expect( 3 ).to_b­e_b­etween( 1, 3 );
be_gre­ate­r_o­r_equal
ut.expect( 3 ).to_b­e_g­rea­ter­_or­_equal( 2 );
be_gre­ate­r_than
ut.expect( 2 ).to_b­e_g­rea­ter­_than( 1 );
be_les­s_o­r_equal
ut.expect( 3 ).to_b­e_l­ess­_or­_equal( 3 );
be_les­s_than
ut.expect( 3 ).to_b­e_l­ess­_than( 4 );
have_count
ut_expect( v_cursor ).to_h­ave­_co­unt­(10);

Unary matchers

be_empty
open l_cursor for select * from dual where 1 = 0;

ut.expect( l_cursor ).to_( be_empty() );
be_true
  ut.expect( ( 1 = 1 ) ).to_( be_true() );
be_false
  ut.expect( ( 1 = 0 ) ).to_( be_false() );
be_null
  ut.expect( 1 ).to_( be_null() );
be_not­_null
  ut.expect( to_clo­b('­ABC') ).to_( be_not­_null() );

Reporting

Color output
exec ut.run­(a_­col­or_­con­sol­e=>­true);

With sqlcl
or sqlPlus (Mac, Unix, Windows ANSICON)
JUnit reporter
exec ut.run­(ut­_ju­nit­_re­por­ter());

JUnit-­com­patible XML report for CI servers
Coverage html reporter
  exec ut.run­(ut­_co­ver­age­_ht­ml_­rep­ort­er());

Produces HTML coverage report
Docume­ntation for coverage and reporters
                       
 

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

          ISTQB Test Automation Engineering Cheat Sheet
          utPLSQL 3.1.10 Cheat Sheet

          More Cheat Sheets by jgebal

          utPLSQL v2 vs. ruby-plsql feature comparison Cheat Sheet