Issue 14 in yatspec: @BeforeClass annotation causes NullPointerException

35 views
Skip to first unread message

yat...@googlecode.com

unread,
Mar 20, 2012, 12:28:17 PM3/20/12
to yat...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

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.


yat...@googlecode.com

unread,
Mar 20, 2012, 12:42:25 PM3/20/12
to yat...@googlegroups.com

Comment #1 on issue 14 by t.m.akeh...@gmail.com: @BeforeClass annotation
causes NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14

Adding a @Before in addition to the @BeforeClass seems to work around this
problem

yat...@googlecode.com

unread,
Mar 20, 2012, 1:07:37 PM3/20/12
to yat...@googlegroups.com

Comment #2 on issue 14 by t.m.akeh...@gmail.com: @BeforeClass annotation
causes NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14

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.

yat...@googlecode.com

unread,
Mar 20, 2012, 1:36:53 PM3/20/12
to yat...@googlegroups.com

Comment #3 on issue 14 by alex.lu...@gmail.com: @BeforeClass annotation
causes NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14

Unable to reproduce this locally with a long running @BeforeClass method
(tried up to 60 seconds).

Can you attach a failing code sample?

yat...@googlecode.com

unread,
Mar 20, 2012, 1:48:02 PM3/20/12
to yat...@googlegroups.com

Comment #4 on issue 14 by t.m.akeh...@gmail.com: @BeforeClass annotation
causes NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14

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.

yat...@googlecode.com

unread,
Mar 21, 2012, 6:51:08 AM3/21/12
to yat...@googlegroups.com

Comment #5 on issue 14 by t.m.akeh...@gmail.com: @BeforeClass annotation
causes NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14

The attached project reliably reproduces the problem on my machine.

Attachments:
yatspec-beforeclass-issue.zip 6.9 KB

yat...@googlecode.com

unread,
Apr 2, 2012, 6:36:16 AM4/2/12
to yat...@googlegroups.com

Comment #7 on issue 14 by t.m.akeh...@gmail.com: @BeforeClass annotation
causes NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14

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?

yat...@googlecode.com

unread,
Apr 2, 2012, 6:42:20 AM4/2/12
to yat...@googlegroups.com

Comment #8 on issue 14 by t.m.akeh...@gmail.com: @BeforeClass annotation
causes NullPointerException
http://code.google.com/p/yatspec/issues/detail?id=14

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

Reply all
Reply to author
Forward
0 new messages