I have the following Junit test
@Before
public void setup() {
UUTClass myObject = new UUTClass();
}
@After
public void teardown() {
// cleanup
}
@Test
public void testSomeMethod() {
myObject.invokeSomeMethod(); // This is throwing NPE from somewhere inside my UUTClass
}
I don't want to use expected=NullPointerException.class
what I want is log the stack trace from my UUTClass. All I can see is a NullPointerException
one liner in my test method.
I am using Log4j to log everything and I have got log4j.xml in the search path which does get picked up by Initializer. I can see my logger messages being printed for other items.
How to enable Junit to return/propagate the full stack trace for NPE that's been thrown by my UUTClass? I believe it's probably because the errors are redirected to error console and perhaps not being picked up by log4j (don't know if I explained that right).
As a workaround, I will probably use printStackTrace()
for now. but ideally I would like to log it if possible.
My Intention is the first understand where in the design I have missed out conditions/constraints which resulted into this NPE and then build more tests to expect certain exceptions. Regards,