shivadorepally / junitparams

Automatically exported from code.google.com/p/junitparams
0 stars 0 forks source link

NullPointerException using @BeforeClass @AfterClass method #30

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I get the following excpetion if use the @BeforeClass/@AfterClass method with 
junit 4.10 (not tested with other junit version):
java.lang.NullPointerException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    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)

A simple test class to reproduce the problem is the following:

@RunWith(JUnitParamsRunner.class)
public class TestProva {

    @BeforeClass
    static public void before() throws Exception {
        return;
    }

    @AfterClass
    public void after() {
        return;
    }

    @Test
    @Parameters(method = "getParam")
    public void test(String param) {
        System.out.println(param);
        return;
    }

    public static Collection<String> getParam() {
        List<String> params = new ArrayList<String>();
        params.add("Param1");
        params.add("Param2");
        return params;
    }
}

Original issue reported on code.google.com by gberti69 on 26 Oct 2012 at 8:47

GoogleCodeExporter commented 8 years ago
@AfterClass needs to be static. Works fine for correct test class.

Original comment by lipinski...@gmail.com on 14 Dec 2012 at 4:12