How to print string messages using JUnit even if the test method is passing?

2.7k views Asked by At

I want print string message for passed test cases. I am able to print message for failure cases using fail() method. How can I print message for pass cases?

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");
    }

}

code of 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>
1

There are 1 answers

0
shinta4ever On

So, I have been looking for an answer for this for a while, and it is hinted at on how to customize your html reports to include passing tests by changing the junit-frames.xsl in the ant script. For passing tests, you can display the message by creating a new template in the default junit-frames.xsl in the following code.

        <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>

and right below.

<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>

Using the same template for display-failures will print out the message for passing tests. Also, make sure your build.xml calls the customized junit-frames.xsl and not the one from the library.