Skip to content

NestedRunner doesn't work with SpringClassRule and SpringMethodRule #8

@BenoitAverty

Description

@BenoitAverty

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions