Why does TestNG have the possibility to check if one of several exceptions are thrown? As far as I know, JUnit only supports one expected exception. Consider the following TestNG dummy examples where both tests will pass:
@Test(expectedExceptions = { NullPointerException.class, IllegalArgumentException.class })
public void throwsNullPointer() {
throw new NullPointerException();
}
@Test(expectedExceptions = { NullPointerException.class, IllegalArgumentException.class })
public void throwsIllegalArgument() {
throw new IllegalArgumentException();
}
My initial feeling is that it should be possible to derive from the code under test exactly which exception that is expected. However, there muse be some design decision from the people behind TestNG.
Is it perhaps support for testing code with random features that cannot be mocked away? Does anybody have an idea, and preferably a real-life scenario?
Aucun commentaire:
Enregistrer un commentaire