<asserts><assert id="myId" type="my.class.Type" hint="myParseHint" action="MYACTION">...</assert><asserts>
For implementing a solid support of assertion features the JUnit-Addons library from Sourceforge is added as utility archive under the terms of the Apache Software License. The possibilities of defining asserts is mapped directly on the assert methods as defined inside of JUnit and JUnit-Addons. The following actions are implemented for now:
Name | Description |
---|---|
isEqual | Maps to JUnit Assert.assertEquals(). |
isNotEqual | Maps to JUnit-Addons Assert.assertNotEquals(). |
isSame | Maps to JUnit Assert.assertSame(). |
isNotSame | Maps to JUnit-Addons Assert.assertNotSame(). |
isNull | Maps to JUnit Assert.assertNull(). |
isNotNull | Maps to JUnit-Addons Assert.assertNotNull(). |
isTrue | Maps to JUnit Assert.assertTrue(). |
isFalse | Maps to JUnit-Addons Assert.assertFalse(). |
isContainedIn | Maps to JUnit-Addons Assert.assertTrue(((Collection)obj).contains(actual)). |
isNotContainedIn | Maps to JUnit-Addons Assert.assertFalse(((Collection)obj).contains(actual)). |
used for java.lang.Compareable | |
isLT | actual is smaller as expected. |
isNotLT | actual is not smaller (greater or equal) as expected. |
isGT | actual is greater as expected. |
isNotGT | actual is not greater (smaller or equal) as expected. |
isInRange | actual is in specified range according to Comparable rules. |
isNotInRange | actual is not in specified range according to Comparable rules. |
The possibility of defining asserts inside of xml gives two advantages over directly using the obj tag and plain %junit; asserts inside the code.
<assert id="complete" action="isEqual" type="junitx.ddtunit.resources.SimpleVO"> <doubleValue>12.4</doubleValue> <integerValue>4711</integerValue> <stringValue>My Text</stringValue> </assert>
public void testMyService(){ SimpleVO simpleVO = MyServiceUnderTest.getSimpleVO(); addResultToAssert("complete", simpleVO); }
To be complete: There are three methods defined under DDTTestCase
As the class DDTTestCase is a direct derivation of JUnit
TestCase it is possible to use all assert methods of
junit.framework.Assert directly in the code. It is also possible
to use your own assertion extensions in the testmethod.
Because the provided testdata change, so do the required assertions.
As a rule of thump use this kind of assertions every time you have correlation
with parameter data of xml resources. This provides information about the
contract or specification you want to test.
What are JUnit assert methods good for?
Every time you want to check pre or post conditions of a data centric check use
JUnit assert methods. These should be used similar to the Java assert
extension. For example if you want to check the result of a customer list
returned by a business function.
The assert action isContainedIn is used to validate if an object is in a specified set of objects. To define such an assert you must specify a Collection containing expected values. For example:
<assert id="testResult" type="java.util.Vector" hint="collection" valuetype="boolean" action="isContainedIn"> <item>true</item> <item>false</item> </assert>
The assert action isInRange is used on java.lang.Comparable datatypes to validate if an object is in a specified range. To define such an assert you proceed as in the following example.
<assert id="result" type="range" action="isInRange"> <startIncluded>false</startIncluded> <start type="long">4711</start> <endIncluded>false</endIncluded> <end type="long">4759</end> </assert></asserts>