Menu

Using JUNIT Report format other than exising

Help
2010-05-02
2012-09-15
  • Lior Kinsbruner

    Lior Kinsbruner - 2010-05-02

    Hi,

    I would like to get a junit report in addition to the html based report that
    jsystem is providing.

    I’ve noticed this report: ‘reports.0.xml’ under log/current, but it is not in
    a pure junit report format.

    How can I produce a pure junit report for my tests execution on jsystem? Once
    I know how to produce such report I will be able to use it in our continuous
    integration environment (MAVEN)

     
  • Golan Derazon

    Golan Derazon - 2010-05-02

    There is not out of box solution for your need.

    You need to find the Junit code that generated the report and convert it to a
    JSystem reporter.

    (it should be easy, since JSystem reporting mechanism support JUnit events)

     
  • Chen Cohen

    Chen Cohen - 2010-05-03

    As I understand jsystem framework, and please correct me if I’m wrong, in
    order to do so I need to:

    • Implement some (jsystem) reporter interface.
    • Add it to reporter.classes property at the jsystem.propertires file.
    • The code that generates this junit report should reside in this implementing class.

    Does that make sense?

    Can you provide some more details about which (jsystem) reporter interfaces I
    need to implement and how does the code that generate junit report looks like?

    Thanks.

     
  • Anonymous

    Anonymous - 2011-01-20

    Searching for solution of the same issue. Thinking about temporary workaround
    with processing reports.0.xml using XSL. But suppose there should be simpler
    way. If anyone knows the solution, please inform

     
  • Anonymous

    Anonymous - 2011-03-17

    Similar problem here. Would like to run tests in a continous integration setup
    with Jenkins (Hudson). But Jenkins does not have a plugin to read JSystem
    output. It does work well however with JUnit directly.

    Been looking into this already for quite some hours (days in fact).

    Just found out a next step into the direction i want. editing the scenario
    xml file
    (which is actually an ant file)

    The jsystem ant-task within these scenario files is apparently similair to the
    junit ant-task. So adding a formatter nested element causes the junit xml
    output to be generated.

    So in your myScenario.xml file which has something like

       ...
        <target name="t1">
            <jsystem showoutput="true">
                <sysproperty key="jsys...
      ...
                <test name="myTestName"/>
            </jsystem>
        </target>
    ...
    

    for each test. Add a line:

    <formatter type="xml"/>
    

    , i.e.

       ...
        <target name="t1">
            <jsystem showoutput="true">
                <sysproperty key="jsys...
      ...
                <test name="myTestName"/>
                <formatter type="xml"/>
            </jsystem>
        </target>
    ...
    

    and the junit xml output will be generated in the current directory.
    (Optionally you might want specify a specific output directory by adding

    todir="${junit.output.dir}"
    

    to the test tag, i.e.

                <test name="myTestName" toDir="${junit.output.dir}" />
    

    )

    This is a good step in the direction I want. Problem remaining though is that
    when I use JRunner to update the scenario it will overwrite these changes in
    myScenario.xml and will have to do it all over again.

    Maybe it is possible to do this differently somehow from JRunner. But didn't
    find a way yet... Anybody else know how to do this?

     
  • Anonymous

    Anonymous - 2011-03-18

    Found another approach that seems to work for me. Thought I'd share it such
    that others can use it if applicable.

    I have created an xsl file that transform the xml report output file
    (reports.0.xml) into a junit format, i.e.

    <xsl:stylesheet version="1.0" xmlns:xsl="[url]http://www.w3.org/1999/XSL/Transform[/url]">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
            <xsl:for-each select="reports">
                <testsuite hostname="{@Station}" name="{@Scenario}" timestamp="{@Date}">
                    <xsl:attribute name="tests">
                        <xsl:value-of select="count(test)"/>
                    </xsl:attribute>
                    <xsl:attribute name="errors">0</xsl:attribute>
                    <xsl:attribute name="failures">
                        <xsl:value-of select="count(test[@status='false'])"/>
                    </xsl:attribute>
    <!--        
                    Need to find a way to determine endtime of whole suite 
                    (start time is given in startTime attribute of reports tag)
                    <xsl:attribute name="time">0</xsl:attribute>
    !-->
                    <properties>
                        <property name="User" value="{@User}"/>
                        <property name="Version" value="{@Version}"/>
                        <property name="startTime" value="{@startTime}"/>
                        <property name="status" value="{@status}"/>
                        <property name="Setup" value="{@Setup}"/>
                    </properties>
                    <xsl:for-each select="test">
                        <testcase classname="{@package}" name="{@name}">
                            <xsl:variable name="tEnd">
                                <xsl:value-of select="@endTime"/>
                            </xsl:variable>
                            <xsl:variable name="tTotalEnd">
                                <xsl:value-of select="$tEnd"/>
                            </xsl:variable>
                            <xsl:variable name="tStart">
                                <xsl:value-of select="@startTime"/>
                            </xsl:variable>
                            <xsl:attribute name="time">
                                <xsl:value-of select="($tEnd - $tStart) * 0.001"/>
                            </xsl:attribute>
                            <xsl:if test="@status = 'false'">
                                <failure type="junit.framework.AssertionFailedError">
                                    <xsl:value-of select="@failCause"/>
                                </failure>
                            </xsl:if>
                        </testcase>             
                    </xsl:for-each>
                    <system-out>
                    </system-out>
                    <system-err>
                    </system-err>
                </testsuite>    
            </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>
    

    Executing the transformation can be done from e.g. ant:

    Saving the above into a file jsystemToJUnitTransformer.xsl and then adding an
    ant target like

        <target name="transformOutput">
            <xslt in="reports.0.xml" out="reports.0_transform.xml" style="jsystemToJUnitTransformer.xsl"/>
        </target>
    

    does the trick.

     

Log in to post a comment.