提交 f47a6a41 编写于 作者: K kohsuke

Further improved the JUnit report parsing.

    (<a href="http://www.nabble.com/NPE-%28Fatal%3A-Null%29-in-recording-junit-test-results-td23562964.html">report</a>)


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18174 71c3de6d-444a-0410-be80-ed276b4c234a
上级 8ff7421a
......@@ -38,7 +38,14 @@ import java.text.ParseException;
*/
public final class CaseResult extends TestObject implements Comparable<CaseResult> {
private final float duration;
/**
* In JUnit, a test is a method of a class. This field holds the fully qualified class name
* that the test was in.
*/
private final String className;
/**
* This field retains the method name.
*/
private final String testName;
private final boolean skipped;
private final String errorStackTrace;
......@@ -91,8 +98,20 @@ public final class CaseResult extends TestObject implements Comparable<CaseResul
// // Maven seems to skip classname, and that shows up in testSuite/@name
// cn = parent.getName();
/*
According to http://www.nabble.com/NPE-(Fatal%3A-Null)-in-recording-junit-test-results-td23562964.html
there's some odd-ball cases where testClassName is null but
@name contains fully qualified name.
*/
String nameAttr = testCase.attributeValue("name");
if(testClassName==null && nameAttr.contains(".")) {
testClassName = nameAttr.substring(0,nameAttr.lastIndexOf('.'));
nameAttr = nameAttr.substring(nameAttr.lastIndexOf('.')+1);
}
className = testClassName;
testName = testCase.attributeValue("name");
testName = nameAttr;
errorStackTrace = getError(testCase);
errorDetails = getErrorMessage(testCase);
this.parent = parent;
......
......@@ -26,9 +26,19 @@ package hudson.tasks.junit;
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import static hudson.model.Result.UNSTABLE;
import hudson.model.FreeStyleProject;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.FreeStyleBuild;
import hudson.scm.SubversionSCM;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.Launcher;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.TestBuilder;
import java.io.IOException;
/**
* @author Kohsuke Kawaguchi
......@@ -50,4 +60,24 @@ public class CaseResultTest extends HudsonTestCase {
assertTrue(tc.getStderr().contains("stderr"));
assertTrue(tc.getStdout().contains("stdout"));
}
@Email("http://www.nabble.com/NPE-%28Fatal%3A-Null%29-in-recording-junit-test-results-td23562964.html")
public void testIssue20090516() throws Exception {
FreeStyleProject p = createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.getProject().getWorkspace().child("junit.xml").copyFrom(
getClass().getResource("junit-report-20090516.xml"));
return true;
}
});
p.getPublishersList().add(new JUnitResultArchiver("*.xml"));
FreeStyleBuild b = assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get());
TestResult tr = b.getAction(TestResultAction.class).getResult();
assertEquals(3,tr.getFailedTests().size());
CaseResult cr = tr.getFailedTests().get(0);
assertEquals("org.twia.vendor.VendorManagerTest",cr.getClassName());
assertEquals("testGetVendorFirmKeyForVendorRep",cr.getName());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册