Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestedRunner doesn't work with SpringClassRule and SpringMethodRule #8

Open
BenoitAverty opened this issue Apr 11, 2016 · 1 comment

Comments

@BenoitAverty
Copy link

I'm trying to use the Spring Junit Rules (SpringClassRule and SpringMethodRule) with the NestedRunner, but I'm getting a NullPointerException at the start of the tests.

Here is a minimal example :

@RunWith(NestedRunner.class)
@SpringApplicationConfiguration(value=ExampleContext.class)
public class TestTest {

    @ClassRule
    public static final SpringClassRule springClassRule = new SpringClassRule();

    @Rule
    public final SpringMethodRule springMethodRule = new SpringMethodRule();

    @Test
    public void firstTest() {
        org.junit.Assert.assertTrue(true);
    }

}
@Configuration
class ExampleContext {
}

and the error :

java.lang.NullPointerException
    at org.springframework.test.context.junit4.rules.SpringClassRule.apply(SpringClassRule.java:140)
    at org.junit.rules.RunRules.applyAll(RunRules.java:26)
    at org.junit.rules.RunRules.<init>(RunRules.java:15)
    at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:245)
    at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:194)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:362)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

If I comment out the @RunWith annotation, then it works fine.

@Macroz
Copy link
Member

Macroz commented Sep 26, 2016

Hi sorry for the long delay in answering.

This Runner was built a long time ago, and without @rule support. Maybe you can get away with the new JUnit5 functionality? http://junit.org/junit5/docs/current/user-guide/#writing-tests-nested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants