I applied a general test for methods hashCodeand equalsusing the JUnit experimental annotation @Theory. The test case class itself is based on the dfa version .
However, when I tried to test the class java.net.InetAddress, I ran into a particular problem if the method providing the data contains code that throws an exception (in this case UnknownHostException):
So, I tried two alternatives that led to the same unsatisfactory result:
Declare the method as the appropriate exception:
@DataPoints
public static InetAddress[] declareException() throws UnknownHostException {
return new InetAddress[] {
InetAddress.getByName("not a valid internet address")
};
}
Explicitly catch the exception and re-throw as AssertionError:
@DataPoints
public static InetAddress[] rethrowAsAssertionError() {
try {
return new InetAddress[] {
InetAddress.getByName("not a valid internet address")
};
} catch(UnknownHostException ex) {
throw new AssertionError(ex);
}
}
a AssertionError " , . : []", @DataPoints.
- , JUnit (, , ) JUnit?