Assert Actions
Assert actions are used in the action
attribute of the assert tag.
The following values are valid:
- ISNULL
- ISNOTNULL
- EQUALS
- NOTEQUALS
- GT (greater than)
- NOTGT (not greater than)
- LT (less than)
- NOTLT (not less than)
- ISTYPEOF
- ISTRUE
The type
attribute of the assert
tag defines the data type to the assertion value.
Assert action isTypeOf
<method name="testTypeOf" test-case="standard">
<asserts>
<assert name="variable" type="org.jtestcase.CustomType" action="ISTYPEOF"></assert>
</asserts>
</method>
/**
* Assert TypeOf Action
*
* @throws Exception
*/
public void testTypeOf() throws Exception {
Vector testCases = null;
String dataFile = "test/org/jtestcase/data/AssertTest1.xml";
_jtestcase = new JTestCase(dataFile, "AssertTest");
testCases = _jtestcase.getTestCasesInstancesInMethod("testTypeOf");
// for each test case
for (int i = 0; i < testCases.size(); i++) {
TestCaseInstance testCase = (TestCaseInstance) testCases.get(i);
boolean succeed = testCase.assertTestVariable("variable",
new CustomType());
assertTrue("Assertion unexpectedly failed", succeed);
}
}
|
Assert action isTrue
<method name="testIsTrue" test-case="standard">
<asserts>
<assert name="variable" type="org.jtestcase.CustomType" action="ISTRUE"></assert>
</asserts>
</method>
/**
*
* @throws Exception
*/
public void testIsTrue() throws Exception {
Vector testCases = null;
String dataFile = "test/org/jtestcase/data/AssertTest1.xml";
_jtestcase = new JTestCase(dataFile, "AssertTest");
testCases = _jtestcase.getTestCasesInstancesInMethod("testIsTrue");
// for each test case
for (int i = 0; i < testCases.size(); i++) {
TestCaseInstance testCase = (TestCaseInstance) testCases.get(i);
boolean assert1succeed = testCase.assertTestVariable("variable",
new Boolean(true));
assertTrue("Assertion unexpectedly failed", assert1succeed);
}
}
|