Getting custom attribute from an Exception thrown during testing

Posted by Amit Bhargava on Stack Overflow See other posts from Stack Overflow or by Amit Bhargava
Published on 2012-03-19T09:54:33Z Indexed on 2012/03/19 10:03 UTC
Read the original article Hit count: 263

Filed under:
|
|

I'm using JUnit4 to test my code.

Now, I'm aware that the following annotation allows me to expect an exception of a certain type

@Test(expected = NipException.class)

However, I have an 'errorCode' property in my exception class which I would also like to verify.

This is because the same exception is thrown at three places in the same method with different error codes.

How do I access 'errorCode' of the thrown exception?

© Stack Overflow or respective owner

Related posts about java

Related posts about unit-testing