Professional Documents
Culture Documents
TAFJ UnitTestFramework
TAFJ UnitTestFramework
R16
TAFJ-U ni tT e s t F r a m e w o r k
Amendment History:
Revisio
Date Amended Name Description
n
1 Sep 11 2015 T. Aubert Initial version
2 Nov 5 2015 T. Aubert New functionalities added
3 Dec 15 2015 T. Aubert Removed the recording facilities
Page 2
TAFJ-U ni tT e s t F r a m e w o r k
Ta b l e o f C o n t e n t s
Introduction......................................................................................................................... 6
tut Overview........................................................................................................................ 6
UTF.setTarget(<subroutine>)..........................................................................................9
UTF.setDescription(<a_description>).............................................................................9
UTF.addParam(<variable_or_value>)............................................................................9
UTF.runTest()............................................................................................................... 10
Stubs methods.................................................................................................................. 10
reference = UTF.addStub(<subroutine>)......................................................................10
UTF.setRepeatable(<a_stub_ref>)...............................................................................10
UTF.addStubCommonChange(<a_stub_ref>,<common>,<out_value>).......................11
UTF.addStubWriteDone(<a_stub_ref>,<table>,<id>, <out_record>)............................12
UTF.addStubPropertyChange(<a_stub_ref>,<component>,<property>, <value>).......13
UTF.setStubReturnValue(<a_stub_ref>, <value>)........................................................13
UTF.getNbInvocation(<a_stub_ref>)............................................................................13
Assertions methods.......................................................................................................... 14
UTF.addParam("7").......................................................................................................... 14
UTF.assertEquals(<value1>, <value2>).......................................................................14
UTF.assertContains(<value1>, <value2>)....................................................................14
UTF.assertTrue(<value>).............................................................................................14
Page 3
TAFJ-U ni tT e s t F r a m e w o r k
UTF.assertFalse(<value>)............................................................................................15
UTF.assertGreaterThan(<value1>, <value2>)..............................................................15
UTF.assertLessThan(<value1>, <value2>)..................................................................15
UTF.assertStartsWith(<value1>, <value2>)..................................................................15
UTF.assertEndsWith(<value1>, <value2>)...................................................................15
UTF.assertMatches(<value1>, <mask>).......................................................................15
UTF.getRecord(<table>, <id>)......................................................................................15
Modifiers........................................................................................................................... 16
UTF.any()..................................................................................................................... 17
UTF.matches(<mask>).................................................................................................17
UTF.same().................................................................................................................. 17
From scratch................................................................................................................18
By Recording............................................................................................................... 19
Editor Helpers................................................................................................................... 22
Adding a stub............................................................................................................... 23
Running tests....................................................................................................................26
In console mode...........................................................................................................26
In Eclipse..................................................................................................................... 28
Reporting.......................................................................................................................... 29
Page 4
TAFJ-U ni tT e s t F r a m e w o r k
Scoping exception........................................................................................................29
Stubbing a method.......................................................................................................29
Page 5
TAFJ-U ni tT e s t F r a m e w o r k
Intro d u c ti o n
The Unit Test Framework (UTF) helps developers and testers to validate that the code is
doing what it is intended to do. The version 1.0 was storing binary informations, and was
requiring a specific editor to modify a tests. Despite that the “binary” way of storing in
formations was a good approach for huge sets of informations, the downsides were too big,
and a full re-engineering has been done to get to the Version 2.
The Version 2 still have the recording facility, and this is much easier to maintain the test as
this ends up being “just” jBC code. However, unlike EasyQA, there is only one file per test
and the full Eclipse launching facilities are still available. This document aims to describe in
details how this all work. You will notice that there is no “deployment” section as everything is
embedded in the existing runtime / compiler / eclipse plugins.
t u t Ov e rvi e w
A .tut file is a jBC file. However, the extension .tut is necessary to help the different tools to
discover the tests.
A tut is not a SUBROUTINE, neither a PROGRAM nor a FUNCTION. This is a
“TESTCASE”.
So every tuts are starting with TESTCASE <name of test> as shown here :
We could wonder why this could not be a simple SUBROUTINE or PROGRAM, and later in
the document, everything will make sense. For now, we simply need to know that a UnitTest
is declared in the code with TESTCASE.
Then, this is just jBC, anything jBC can do can be done in a tut. However, this would not be
really useful to stop at that point, and this is here that the TESTCASE declaration starts to
make sense. In fact, by using TESTCASE, this will automatically add a low-level reference in
the code. This reference is “UTF”. IN the next chapter, we will describe all the methods the
UTF reference (object) is offering. We will call it a “component” to make the reading more jBC
oriented, but in fact this is a real Object.
T h e U T F “C o m p o n e n t ”
So we know now that a Temenos Unit Test is a file with the “tut” extension that this is written
in jBC and that the declaration is “TESTCASE” because we need the “UTF Component”
which will help us doing a test. So let's look in details at this Component.
Page 6
TAFJ-U ni tT e s t F r a m e w o r k
First, this is a low-level component, sitting into the runtime, so don't try to find something like
UTF.component on your disk, it doesn't exists. Then, this component is automatically “here”.
No need to do a $USING or whatsoever, it sits behind your code. You can consider it as a
language extension. Let's explore all these extensions. The full list :
Global methods :
UTF.runTest()
UTF.setTarget(<subroutine>)
UTF.setDescription(<a_description>)
UTF.addParam(<variable_or_value>)
UTF.runTest()
Stubs methods :
UTF.addStub(<subroutine>)
UTF.setRepeatable(<a_stub_ref>)
UTF.setStubReturnValue(<a_stub_ref>, <value>)
Assertions methods :
UTF.assertEquals(<value1>, <value2>)
UTF.assertContains(<value1>, <value2>)
UTF.assertTrue(<value>)
UTF.assertFalse(<value>)
Page 7
TAFJ-U ni tT e s t F r a m e w o r k
UTF.assertGreaterThan(<value1>, <value2>)
UTF.assertLessThan(<value1>, <value2>)
UTF.assertStartsWith(<value1>, <value2>)
UTF.assertEndsWith(<value1>, <value2>)
UTF.assertMatches(<value1>, <mask>)
UTF.getRecord(<table>, <id>)
Modifiers methods :
UTF.any()
UTF.matches(<mask>)
UTF.same()
Page 8
TAFJ-U ni tT e s t F r a m e w o r k
Gl o b a l U T F M e t h o d s
U TF. s e tT ar g e t ( < s u b r o u t i n e > )
Usually the very first method (but not mandatory), this is defining what subroutine we want to
test. This subroutine will be called with the UTF.runTest() method described later.
XYZ = "TEST.SIMPLE"
UTF.setTarget(XYZ)
or
UTF.setTarget("TEST.SIMPLE")
Note that this will be always the same for all parameter, so we won't repeat it.
P1 = "7"
UTF.addParam(P1)
DIM P2(10)
P2(2) = "6"
UTF.addParam(P2)
Page 9
TAFJ-U ni tT e s t F r a m e w o r k
U TF.r u nT e s t ( )
This method simply launch the test (call the routine defined by the setTarget(...). This method
must be called after the stubs definition (see next section)
If the routine defined by the setTarget is a FUNCTION, then UTF.runTest() will return the
value of the function.
Eg :
ret.value = UTF.runTest()
Stubs m ethods
STUB = UTF.addStub("DO.SOMETHING")
Note that the return value is a function. You cannot do a lot with it appart passing it back to
the next stub related functions.
The section describing how the stubs are found (later in this document) will certainly bring
some lights.
Page 10
TAFJ-U ni tT e s t F r a m e w o r k
U TF. a d d S t u b P a r a m ( < a_ s t u b_r e f > , < i n_v a l u e > , < o u t_v a l u e > )
This method has to be invoked as many times as the number of parameters in your stub. In
DO.SOMETHING, we have 3 parameters, so we need to invoke 3 times
UTF.addStubParam(...). The first parameter is the stub references (obtained when doing
UTF.addStub), the second one is the in-parameter, the third one is the value of this
parameter after the call. We could argue about the in-parameter need. This one is used to
detect which stub needs to be called. If we take the same CDT function, we will have
STUB = UTF.addStub("CDT")
STUB = UTF.addStub("CDT")
When the target calls CDT('', 20130623, “+1C”), then the 2nd parameter changes to
20130624. The tests needs to know which one to take. This explain the in-parameter.
Note that STUB is just a variable name, you can put anything you want.
MY.FIRST.STUB = UTF.addStub("CDT")
. . .
Page 11
TAFJ-U ni tT e s t F r a m e w o r k
If your common is an DIMmed array (eg R.NEW), you will pass an array as new value :
DIM stubCommon(500)
U TF. a d d S t u b Wri t e D o n e ( < a_ s t u b_r e f > , < t a b l e > , < i d > , < o u t_r e c o r d > )
Exactly the same as the previous one, but for database.
So doing
is the same as if the routine were doing a F.WRITE. Of course, the database is not touched,
but this is “as if ...”
Page 12
TAFJ-U ni tT e s t F r a m e w o r k
Return the number of time a stub got invoked during the test
example (check that our stub got invoked 2 times) :
NB.STUB = UTF.getNbInvocation(STUB)
UTF.assertEquals(2, NB.STUB)
Page 13
TAFJ-U ni tT e s t F r a m e w o r k
As s ertio n s m e t h o d s
These methods are obvious and talking by themselves. If one of these method is evaluated
as “false”, the test will be in “failure”. Please refer to the “reporting” and “eclipse” chapters for
more details.
At the beginning of the document, we mentioned that the parameters should be put as
variables and not constant. Imagine that you wrote
UTF.addParam("7")
Instead of
P1 = "7"
UTF.addParam(P1)
UTF.assertEquals(P1, "7")
Page 14
TAFJ-U ni tT e s t F r a m e w o r k
eg
UTF.assertMatches(P1, "3N4X")
P1 = "123ABCD" : TRUE
P1 = "123ABC" : FALSE
Page 15
TAFJ-U ni tT e s t F r a m e w o r k
M o difi er s
This section should in fact be linked to the Stubs, but for clarity of the documents let's keep it
at the end. Modifiers are informations you can pass as arguments to the stub definitions.
When a test is running, and the target is making a CALL, the UTF is looking for the best
matching stub. The first absolute test is the stub name (the SUBROUTINE name must match
EXACTELY the call -obvious-). Then, we will check the parameters.
If all the parameters are “normally” defined, then they must match exactly as well, however,
we can put modifiers so the stub could not fully match.
Example :
Means that whatever the in parameter is, this stub will be eligible for the CALL and the
parameter will be changed to "Anything"
Means that if the in parameter Matches "2N", this stub will be eligible for the CALL and the
parameter will be changed to "less than hundred"
The stubs are sorted by <number of strict value>, <number of match value> and <number of
“any” value>. The top most stub will be taken.
Page 16
TAFJ-U ni tT e s t F r a m e w o r k
U TF. a n y ( )
Do not consider the parameter to elect the stub as a good stub for a given CALL.
U TF. s a m e ( )
UTF.same() is not a modifier as such. It is defined for the out-parameter. This is basically
saying that the out parameter ends up having the same value as the in. As an example, this
parameter :
Would not change the parameter if this is a 2 digit number, and of course, if there is no better
match (eg UTF.addStubParam(STUB, "12", "twelve"))
Page 17
TAFJ-U ni tT e s t F r a m e w o r k
Cr e a t i n g a n e w U n i tT e s t
Fr o m s c r a t c h
Creating a test is not any different than creating a new SUBROUTINE : In Eclipse, Right-click
on the directory where you want to create your test, select
Page 18
TAFJ-U ni tT e s t F r a m e w o r k
Page 19
TAFJ-U ni tT e s t F r a m e w o r k
Edit or H e l p er s
When editing a TESTCASE, you have some options in the contextual menu of your editor.
Righ-click on the editor (where you want to add something). You will have the “Unit Test
Framework ….” menu available with 2 options : “Setting the target...” and “Adding a stub...”
S e tti n g t h e tar g e t
This option will open the JBC Subroutine selection dialog (see specific chapter).
Select a routine or component method, and the code for setting the target with all parameters
will be added. You only will need to specify the values of the parameters.
UTF.setTarget("AA.Fees.CalculateTierAmount")
TierGroup = ''
UTF.addParam(TierGroup)
TierType = ''
UTF.addParam(TierType)
. . .
ChargeCalcDetails = ''
UTF.addParam(ChargeCalcDetails)
RetError = ''
UTF.addParam(RetError)
Page 20
TAFJ-U ni tT e s t F r a m e w o r k
Ad d i n g a s t u b
Adding a stub is done the same way as setting the target. The code will be generated like
this ( for AC.API.EbUpdateAcctEntFwd )
STUB = UTF.addStub("AC.API.EbUpdateAcctEntFwd")
The default values are UTF.any() for the IN param and UTF.same() for the OUT param. You
will need to change these values according to your test case.
Page 21
TAFJ-U ni tT e s t F r a m e w o r k
JBC S u b r o u t i n e s e l e c t i o n d i a l o g
The precedent chapter is mentionning this dialog box, and here is a description of how it
works.
IMPORTANT : The contents of this dialog box IS NOT THE SOURCE files, but the
compiled one. This means you don't need to have all sources to be able to select a
routine. Just have the jars in your precompile directory.
Page 22
TAFJ-U ni tT e s t F r a m e w o r k
Co nv erti n g o l d t ut s
There is a tool to convert tut version 1.0 to the new 2.0 version.
In the TAFJ/bin directory, you will find the tConvertTest (.bat file).
The syntax is :
If the new file is omitted, the <file_to_convert> will be overridden by the new one.
A test acts as a jBC PROGRAM or SUBROUTINE. There compile the same way, a Class is
generated, this class can be put in a jar.
Page 23
TAFJ-U ni tT e s t F r a m e w o r k
Runnin g tests
In c o n s ol e m o d e
Running a test is not very different as running a program. There is only one flag to specify : “-
test”. This flag is necessary as the class generated is prefixed with “testcase.” to not conflict
with the target subroutine.
To resume :
example : tRun MY.SUBROUTINE will try to run the class MY_SUBROUTINE_cl.class which
is wrong. You have to run :
So this is
TESTCASE myTest
You can also run your test by specifying the full file name.
Example :
Page 24
TAFJ-U ni tT e s t F r a m e w o r k
Run ni n g m ultiple t e st s at o n c e
You can also specify a directory. In that case, all tests in this directory will be run
Example :
And last but not least, you can use the -recurs flag if you want to find tests resursively in a
directory and run them :
Example :
R et ur n valu e
In console mode, the exit value of tRun will be 1 if one or more test are failing. A success
value is 0.
Note that a failure can be something else than a wrong assertion. It can be a call to a non
existing routine, a test without assertion, or any kind of technical failure.
Page 25
TAFJ-U ni tT e s t F r a m e w o r k
In Eclip s e
Running a test in eclipse consist of selecting
Automatically, a new window will open showing the tests and their results :
Page 26
TAFJ-U ni tT e s t F r a m e w o r k
R e p ortin g
You can generate junit types of reports by specifying it in the properties file with the following
keys :
temn.tafj.utf.generate.results = true
<tafj_home>/data/<projectName>/testResults/
temn.tafj.utf.results.directory = …
C o m p o n e n t a n d U n i tT e s t s
Stubbin g a m et hod
A method can be stubbed by giving it fully qualified name
UTF.addStub(“MOD.Component.myMethod”)
You do not need to explicitly add a $USING for this stub case.
Page 27