General
Add a close *all statement in a tearDown procedure.
Ptest_something b Export
Dtest_something pi
/free
PgmUnderTst( 'something' );
open AFILE;
read ARECORD;
aEqual( 'something' : aField );
close AFILE; // This statement will not be reached if the aEqual assertion fails.
/end-free
P e
PtearDown b Export
DtearDown pi
/free
close *all; // All files opened by the testing program will be closed, no matter what.
/end-free
P e
Yes! Anything you can do with RPG, you can do with RPGUnit. Here is an example of a test with SQL statements.
H NoMain
/copy RPGUNIT1,TESTCASE
D PgmUnderTest pr ExtPgm('YOURPGM')
DsetUp pr
Dtest_something pr
PsetUp b Export
DsetUp pi
C/exec sql
C+ delete from AFILE
C/end-exec
P e
Ptest_something b Export
Dtest_something pi
D aRecord e ds Qualified ExtName(AFILE)
C/exec sql
C+ insert into SOMEFILE values(1, 'A001', 1000)
C/end-exec
C callp PgmUnderTest
C/exec sql
C+ select * into :aRecord from AFILE
C/end-exec
/free
aEqual( '00' : %Subst( SqlState : 1 : 2 ) );
iEqual( 1000 : aRecord.aField );
/end-free
P e
You cannot use the RUCRTTST command to compile this test program. You have to compile the SQLRPGLE member containing the test code as a module, and then turn it into a service program.
===> CRTSQLRPGI OBJ(SQLTST) SRCFILE(SRCFILE) COMMIT(*NONE) OBJTYPE(*MODULE) ===> CRTSRVPGM SRVPGM(SQLTST) EXPORT(*ALL) BNDSRVPGM(RUTESTCASE) ===> RUCALLTST SQLTST