New issue 14 by t.m.akeh...@gmail.com: @BeforeClass annotation causes
NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14
What steps will reproduce the problem?
Add a @BeforeClass annotated method to the JUnit class
What is the expected output? What do you see instead?
I expect my test to pass, but instead it fails and I see this in the
console:
Error while writing yatspec output
java.lang.NullPointerException
at com.googlecode.yatspec.junit.SpecRunner.run(SpecRunner.java:64)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
What version of the product are you using? On what operating system?
193 on Mac OSX Snow Leopard
Please provide any additional information below.
Adding a @Before in addition to the @BeforeClass seems to work around this
problem
OK, playing around with this a little more it seems that only happens with
certain code in the @BeforeClass method. The code I'm using that's breaking
takes a (relative) while to execute, so it might be timing related.
Unable to reproduce this locally with a long running @BeforeClass method
(tried up to 60 seconds).
Can you attach a failing code sample?
Hmmm....that's odd. Maybe it's not a timing thing - the code I'm running
starts a Jetty server, so perhaps it's something to do with that.
I'll try and build and example that's not tied to our project and attach it
tomorrow.
The attached project reliably reproduces the problem on my machine.
Attachments:
yatspec-beforeclass-issue.zip 6.9 KB
Ah ok, looks like an exception being thrown is the problem in our app too.
It's not obvious that this is the case though - yatspec is effectively
swallowing the exception you'd see if this was an ordinary JUnit test and
replacing it with this NPE.
Would it be possible to maintain the default JUnit behaviour and have the
original exception be thrown to the top of the stack?
Apologies, I'm being daft. It's still supplying the right exception the the
test runner. It's just that it dumps the NPE out to the console.
Thanks,
Tom