<asserts><exception id="myId" type="my.exception.Type" hint="myParseHint" action="MYACTION">...</exception><asserts>
In fact a lot of testing goes into checking if certain exceptions are raised
as expected error conditions.
To support this feature in JUnit you would use a code snipplet like this
public void testExpectedException(){
try{
instanceUnderTest.methodUnderTest(myParam);
fail("An exception was expected");
} catch (MyExpectedException e){
// whatever special checks you want to add
// if pass, all is fine
}
}...
public void testExpectedException(){
my.param.Clazz myParam = (my.param.Clazz) getObj("myParam");
instanceUnderTest.methodUnderTest(myParam);
}
...
== with the xml definition:
<test id="testExpectedException">
<objs>
<obj id="myParam" type="my.param.Clazz">Content</obj>
</objs>
<asserts>
<exception id="expectedException" type="my.expected.Exception"
action="isEqual">Message of Exception</exception>
</asserts>
</test>| Name | Description |
|---|---|
| isEqual | Two exceptions are equal if they are of the same type and they contain the same method as defined by getMessage() |
| isSimilar | Two exceptions are similar if they are of the same type and the message of the defined exception is contained in the one of the actual exception. |
| isInstanceOf | One exception object is of the same instance as a specified class type if it has the same type or a derived type as the specified class. |
Here you can see an example taken from the test suite.