NullPointerException in JUnitXmlReportGenerator

(wonnadownload) #1

we use the JavaScript JasmineJUnitTestRunner (@RunWith) which creates a NPE if the names of the tests do not contain parenthesis “()”.

The NPE occurs in test.getName().equals(…) because the getName() returns null.

class JUnitXmlReportGenerator {
    protected void started(TestState state) {
        TestDescriptorInternal test = state.test;
        if (test.getName().equals(test.getClassName())) {
            testSuiteReport = documentBuilder.newDocument();

The reason is in class JUnitTestEventAdapter

private TestDescriptorInternal descriptor(Object id, Description description) {
        return new DefaultTestDescriptor(id, className(description), methodName(description));

where methodName(description) returns null if description.toString() does not contain parenthesis “()”. This creates a test descriptor with name == null.

private String methodName(Description description) {
        Matcher matcher = methodStringMatcher(description);
        if (matcher.matches()) {
        return null;
    private Matcher methodStringMatcher(Description description) {
        return Pattern.compile("(.*)\((.*)\)").matcher(description.toString());