background image
<< Test Class Primitives | Stub Failure Detection >>
<< Test Class Primitives | Stub Failure Detection >>

Stub Sequence Verification

Test RealTime - User Guide
Example
To test that the sum of two Moneys with the same currency contains a value which is
the sum of the values of the two Moneys, write:
public void testSimpleAdd() {
Money m12EUR=new Money(12, "EUR");
Money m14EUR=new Money(14, "EUR");
Money expected= new Money(26, "EUR");
Money result= m12EUR.add(m14EUR);
assertTrue(expected.equals(result));
}
Java Stub Harness
Component Testing for Java supports the following verification methods for stubbed
classes:
·
Stub failure detection
·
Stub sequence mechanism
Stub Mechanism Overview
The Component Testing for Java test harness provides a stub logging mechanism.
The purpose of this mechanism is to check that calls to a stubbed object are achieved
in a correct order.
For each test, the
enter
,
exit
and
fail
methods of the stubbed objects are logged by the
object TestSynchroStub.
You can then query the TestSynchroStub object to:
·
Compare the actual stub
enter
and
exit
sequence against an expected sequence
as defined by the StubSequence object
·
Check for the presence of at least one
fail
method
Use the test harness
assert
or
verify
primitives to add the stub sequence or failure
verification results into a formal test report.
Stub Sequence Verification
Use the StubSequence object to test the stub sequence. This object can be loaded with
the sequence under test. The actual comparison is performed with the corresponding
method of the object TestSynchroStub.
The following example demonstrates how to verify the entry into a method
public void teststub3()
{
NoStub another = new NoStub();
another.call1();
StubSequence testof = new StubSequence(this);
verifyLogMessage("verify one enter method");
testof.addEltToSequence( new StubbedOne().getClass() ,
180