Junit categories with dynamic test suites throws a null pointer exception

Hi all,

I have a problem with running JUnit test suites using categories - my unit test looks like :

@RunWith(AllTests.class)

@Category(Experimental.class)

public class GradleProblemTest {

public static TestSuite suite() throws Exception {

TestSuite suite = new TestSuite();

suite.addTest(new MyTest());

return suite;

}

public static class MyTest implements Test, Describable {

@Override

public int countTestCases() {

return 1;

}

@Override

public void run(TestResult result) {

result.startTest(this);

Protectable p = new Protectable() {

public void protect() throws Throwable {

//doSomething;

}

};

result.runProtected(this, p);

result.endTest(this);

}

@Override

public Description getDescription() {

return Description.createTestDescription(“Test Name”, “Simple test case”);

}

}

}

and my gradle task looks like

task runExperiments (type: Test) {

outputs.upToDateWhen() { false }

useJUnit {

includeCategories ‘com.logicalglue.testing.categories.Experimental’

}

include(’**/runner/GradleProblemTest*’)

}

when I run ‘gradle runExperiments’ i get

:functional-test:compileJava UP-TO-DATE

:functional-test:processResources UP-TO-DATE

:functional-test:classes UP-TO-DATE

:functional-test:compileTestJava

Note: /Users/gazmoorst/Code/LogicalGlue/logical-glue/functional-test/src/test/java/com/logicalglue/testing/api/builders/AbstractListBackedTestStepBuilder.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

:functional-test:processTestResources UP-TO-DATE

:functional-test:testClasses

:functional-test:runExperiments

com.logicalglue.testing.api.runner.GradleProblemTest > initializationError FAILED

java.lang.NullPointerException

1 test completed, 1 failed

:functional-test:runExperiments FAILED

FAILURE: Build failed with an exception.

and the test reports show this error:

java.lang.NullPointerException

at org.junit.runner.Description.createSuiteDescription(Description.java:123)

at org.gradle.api.internal.tasks.testing.junit.CategoryFilter.shouldRun(CategoryFilter.java:47)

at org.junit.internal.runners.JUnit38ClassRunner.filter(JUnit38ClassRunner.java:138)

at org.junit.runner.manipulation.Filter.apply(Filter.java:97)

at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:32)

at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:74)

at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)

at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)

at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)

at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)

at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)

at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)

at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:745)

I can work around it by not implementing Describable, but then the test doesn’t run at all.