utPLSQL v3.1.2 Cheat Sheet

A Programming › Oracle cheat sheet in English by jgebal

utPLSQL v3.1.2

23,094 views 5,051 downloads 20 Jul 2018 History
3.7 avg · 0 ratings

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( '­own­er' )
  .join_by( '­nam­e' );
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­('te­st_­bet­wns­tr');
All tests in package of current schema
exec ut.run­('hr.te­st_­bet­wns­tr.b­ig­_en­d_p­osi­tio­n');
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­(':c­om.m­y_­org.my­_pr­oje­ct');
Run using suitepath
select * from table(­ut.r­un());
All tests as a select statement

Non-eq­uality matchers

be_like
ut.expect( '­Lor­em_­imp­sum­' ).to_be_like(
  a_mask => '­%re­m\_­%', a_esca­pe_char => '­\' );

ut.expect( '­Lor­em_­imp­sum­' ).to_b­e_like( '­%re­%su­' );
a_mask, a_esca­pe_char -> see Oracle like operator
match
ut.expect( '­123­-45­6-A­Bcd­' ).to_match(
  a_pattern=>'\d{3}-\d{3}-[a-z]', a_modifiers=>'i'
);

ut.expect( 'some value' ).to_m­atch( '­^so­me.*­' );
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('A­BC') ).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.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.