background image
<< Stub Sequence Verification | Running a Test Case >>
<< Stub Sequence Verification | Running a Test Case >>

Stub Failure Detection

Automated Testing
"methodone", StubInfo.ENTER) ;
verifyEquals("Test single
sequence",TestSynchroStub.isSeqRespected(testof),true);
}
This example shows how to verify the entry into
methodone
of the class
StubbedOne
and that the method m1 of StubbedTwo has been successively entered and exited.
This is part of the call stack of the methods of stubbed objects.
public void teststub4()
{
NoStub another = new NoStub();
another.call1();
StubSequence testof = new StubSequence(this);
testof = new StubSequence(this);
testof.addEltToSequence( new StubbedOne().getClass() ,
"methodone",StubInfo.ENTER) ;
testof.addEltToSequence( new StubbedTwo().getClass() ,
"m1",StubInfo.ENTER) ;
testof.addEltToSequence( new StubbedTwo().getClass() ,
"m1",StubInfo.EXIT) ;
verifyLogMessage("Check true for stub calls");
verifyEquals("Test single
sequence",TestSynchroStub.isSeqRespected(testof),true);
}
Stub Failure Detection
In the Component Testing for Java test harness, stubs can declare an error by use of
the
fail()
method.
To check for the existence of a stub error, use the following global call type:
verify("Test single
sequence",TestSynchroStub.areStubfail(this),true);
The following example demonstrates the use of TestSynchroStub to test if a stub has
been declared failed.
public void testStubFail()
{
StubbedThree st = new StubbedThree();
st.call();
verifyLogMessage("Check fail call from stub");
verifyEquals("Test single
sequence",TestSynchroStub.areStubfail(this),true);
}
Using the TestCase Class
To create a test case in the Component Testing for Java test harness, create a test class
by deriving from the TestCase of the test harness. Only classes derived from TestCase
can use the test harness services
·
Create a derived class of TestCase:
181