Show Menu

utPLSQL v3.1.2 Cheat Sheet by

utPLSQL v3.1.2
testing     oracle     tdd     unit-testing     utplsql     plsql     unit-test

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 (documentation)

Equality matcher

equal
ut.ex­pect( '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_objects;
open l_actual for select * from all_objects;
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.ex­pect( actua­l_v­alue ).to_( matc­her );
Negated expect­ation
ut.ex­pect( actua­l_v­alue ).not_to( matc­her );
Shortcuts syntax
ut.ex­pect( actua­l_v­alue ).to_matcher;
ut.expect( actua­l_v­alue ).not_­to_­m­atc­her;
 

Executing tests

exec ut.run();
All tests in my current schema
alter session set current_schema='HR';
exec ut.run();
All tests in current schema after it was changed to HR
exec ut.run­('H­R');
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_l­ike
ut.ex­pect( '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.ex­pect( '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_b­etw­een
ut.ex­pect( 3 ).to_b­e_b­etween( 1, 3 );
be_g­rea­ter­_or­_eq­ual
ut.ex­pect( 3 ).to_b­e_g­rea­ter­_or­_equal( 2 );
be_g­rea­ter­_than
ut.ex­pect( 2 ).to_b­e_g­rea­ter­_than( 1 );
be_l­ess­_or­_eq­ual
ut.ex­pect( 3 ).to_b­e_l­ess­_or­_equal( 3 );
be_l­ess­_than
ut.ex­pect( 3 ).to_b­e_l­ess­_than( 4 );
have­_co­unt
ut_ex­pect( v_cursor ).to_h­ave­_co­unt­(10);

Unary matchers

be_e­mpty
open l_cursor for select * from dual where 1 = 0;
ut.expect( l_cursor ).to_( be_empty() );
be_t­rue
ut.expect( ( 1 = 1 ) ).to_( be_true() );
be_f­alse
ut.expect( ( 1 = 0 ) ).to_( be_false() );
be_n­ull
ut.expect( 1 ).to_( be_null() );
be_n­ot_­null
ut.expect( to_clo­b('­ABC') ).to_( be_not­_null() );

Reporting

Color output
exec ut.run(a_color_console=>true);
With sqlcl
or sqlPlus (Mac, Unix, Windows ANSICON)
JUnit reporter
exec ut.run(ut_junit_reporter());
JUnit-compatible XML report for CI servers
Coverage html reporter
exec ut.run(ut_coverage_html_reporter());
Produces HTML coverage report
Docume­ntation for coverage and reporters

Download the utPLSQL v3.1.2 Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/jgebal_utplsql-v3-1-2.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

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

          Selenium WebDriver Cheat Sheet Cheat Sheet
          utPLSQL v2 vs. ruby-plsql feature comparison Cheat Sheet

          More Cheat Sheets by jgebal

          utPLSQL v2 vs. ruby-plsql feature comparison Cheat Sheet