提交 1d671bee 编写于 作者: K kohsuke

Capture the test output from surefire, which puts stdout/stderr in a place...

Capture the test output from surefire, which puts stdout/stderr in a place different from Ant JUnit task.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16411 71c3de6d-444a-0410-be80-ed276b4c234a
上级 d28069b6
......@@ -47,6 +47,15 @@ public final class CaseResult extends TestObject implements Comparable<CaseResul
private transient ClassResult classResult;
/**
* Some tools report stdout and stderr at testcase level (such as Maven surefire plugin), others do so at
* the suite level (such as Ant JUnit task.)
*
* If these information are reported at the test case level, these fields are set,
* otherwise null, in which case {@link SuiteResult#stdout}.
*/
private final String stdout,stderr;
/**
* This test has been failing since this build number (not id.)
*
......@@ -54,10 +63,6 @@ public final class CaseResult extends TestObject implements Comparable<CaseResul
*/
private /*final*/ int failedSince;
CaseResult(SuiteResult parent, String testClassName, Element testCase) {
this(parent,testClassName,testCase.attributeValue("name"), getError(testCase), getErrorMessage(testCase), parseTime(testCase), isMarkedAsSkipped(testCase));
}
private static float parseTime(Element testCase) {
String time = testCase.attributeValue("time");
if(time!=null) {
......@@ -93,16 +98,18 @@ public final class CaseResult extends TestObject implements Comparable<CaseResul
errorStackTrace = getError(testCase);
errorDetails = getErrorMessage(testCase);
skipped = isMarkedAsSkipped(testCase);
stdout = testCase.elementText("system-out");
stderr = testCase.elementText("system-err");
}
/**
* Used to create a fake failure, when Hudson fails to load data from XML files.
*/
CaseResult(SuiteResult parent, String testName, String errorStackTrace) {
this( parent, parent.getName(), testName, errorStackTrace, "", 0.0f, false );
this( parent, parent.getName(), testName, errorStackTrace, "", null, null, 0.0f, false );
}
CaseResult(SuiteResult parent, String testClassName, String testName, String errorStackTrace, String errorDetails, float duration, boolean skipped) {
CaseResult(SuiteResult parent, String testClassName, String testName, String errorStackTrace, String errorDetails, String stdout, String stderr, float duration, boolean skipped) {
this.className = testClassName;
this.testName = testName;
this.errorStackTrace = errorStackTrace;
......@@ -110,6 +117,8 @@ public final class CaseResult extends TestObject implements Comparable<CaseResul
this.parent = parent;
this.duration = duration;
this.skipped = skipped;
this.stdout = stdout;
this.stderr = stderr;
}
private static String getError(Element testCase) {
......@@ -226,6 +235,37 @@ public final class CaseResult extends TestObject implements Comparable<CaseResul
return getOwner().getNumber()-failedSince+1;
}
/**
* The stdout of this test.
*
* <p>
* Depending on the tool that produced the XML report, this method works somewhat inconsistently.
* With some tools (such as Maven surefire plugin), you get the accurate information, that is
* the stdout from this test case. With some other tools (such as the JUnit task in Ant), this
* method returns the stdout produced by the entire test suite.
*
* <p>
* If you need to know which is the case, compare this output from {@link SuiteResult#getStdout()}.
* @since 1.294
*/
@Exported
public String getStdout() {
if(stdout!=null) return stdout;
return getParent().getStdout();
}
/**
* The stderr of this test.
*
* @see #getStdout()
* @since 1.294
*/
@Exported
public String getStderr() {
if(stderr!=null) return stderr;
return getParent().getStderr();
}
@Override
public CaseResult getPreviousResult() {
SuiteResult pr = parent.getPreviousResult();
......
......@@ -143,7 +143,7 @@ public final class SuiteResult implements Serializable {
// one wants to use @name from <testsuite>,
// the other wants to use @classname from <testcase>.
addCase(new CaseResult(this,classname,e));
addCase(new CaseResult(this, e, classname));
}
}
......@@ -163,11 +163,10 @@ public final class SuiteResult implements Serializable {
}
/**
* The stdout of this test. Note that due to the design of the format,
* stdout for the entire {@link SuiteResult} is reported,
* and Hudson cannot tell what portion of the output corresponds to this test.
* The stdout of this test.
*
* @since 1.281
* @see CaseResult#getStdout()
*/
@Exported
public String getStdout() {
......@@ -175,11 +174,10 @@ public final class SuiteResult implements Serializable {
}
/**
* The stderr of this test. Note that due to the design of the format,
* stdout for the entire {@link SuiteResult} is reported,
* and Hudson cannot tell what portion of the output corresponds to this test.
*
* The stderr of this test.
*
* @since 1.281
* @see CaseResult#getStderr()
*/
@Exported
public String getStderr() {
......
......@@ -66,14 +66,14 @@ THE SOFTWARE.
<h3>${%Stacktrace}</h3>
<pre><lo:out value="${it.errorStackTrace}"/></pre>
<j:if test="${!empty(it.parent.stdout)}">
<j:if test="${!empty(it.stdout)}">
<h3>${%Standard Output}</h3>
<pre><lo:out value="${it.parent.stdout}"/></pre>
<pre><lo:out value="${it.stdout}"/></pre>
</j:if>
<j:if test="${!empty(it.parent.stderr)}">
<j:if test="${!empty(it.stderr)}">
<h3>${%Standard Error}</h3>
<pre><lo:out value="${it.parent.stderr}"/></pre>
<pre><lo:out value="${it.stderr}"/></pre>
</j:if>
</l:main-panel>
</l:layout>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册