即使测试方法通过,如何使用JUnit打印字符串消息?
我想要打印通过测试用例的字符串消息。我可以使用即使测试方法通过,如何使用JUnit打印字符串消息?,junit,junit3,Junit,Junit3,我想要打印通过测试用例的字符串消息。我可以使用fail()方法打印故障案例的消息。如何打印通过案例的消息 public class TestCaseTesting extends TestCase { @Test public void testFailTesting() { fail("Fail message"); } @Test public void testpassTesting() { //what method i need to write he
fail()
方法打印故障案例的消息。如何打印通过案例的消息
public class TestCaseTesting extends TestCase {
@Test
public void testFailTesting() {
fail("Fail message");
}
@Test
public void testpassTesting() {
//what method i need to write here to show message of pass cases
//fail("Fail message");
}
}
build.xml的代码
<target name="generate-report">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${reports}\html\" />
</junitreport>
</target>
因此,我已经寻找了一段时间的答案,并暗示了如何通过更改ant脚本中的junit-frames.xsl来定制html报告以包括通过测试。为了通过测试,您可以通过在以下代码中的默认junit-frames.xsl中创建新模板来显示消息
<xsl:when test="failure">
<td>Failure</td>
<td><xsl:apply-templates select="failure"/></td>
</xsl:when>
<xsl:when test="error">
<td>Error</td>
<td><xsl:apply-templates select="error"/></td>
</xsl:when>
<xsl:when test="skipped">
<td>Skipped</td>
<td><xsl:apply-templates select="skipped"/></td>
</xsl:when>
<xsl:otherwise>
<td>Success</td>
<td><xsl:apply-templates select="success"/></td>
</xsl:otherwise>
失败
错误
跳过
成功
就在下面
<xsl:template match="failure">
<xsl:call-template name="display-failures"/>
</xsl:template>
<xsl:template match="error">
<xsl:call-template name="display-failures"/>
</xsl:template>
<xsl:template match="skipped">
<xsl:call-template name="display-failures"/>
</xsl:template>
<xsl:template match="success">
<xsl:call-template name="display-failures"/>
</xsl:template>
使用相同的显示失败模板将打印通过测试的消息。另外,请确保build.xml调用定制的junit-frames.xsl,而不是库中的junit-frames.xsl。打印消息,以便它们准确地显示在哪里?如果从控制台运行测试,打印到stdout的消息将显示在测试输出中。我正在生成html报告,在该报告中,我希望显示通过案例的消息。stdout对于控制台来说很好,但我想在报告中打印消息。当我们使用fail()方法显示失败消息时,是否有任何方法用于传递案例消息。您使用什么来生成HTML报告?您使用什么来执行测试?我使用Ant脚本生成报告请查看此链接