开发者

Junit Reports only showing the last class ran when executed with build.xml

I can get the build.xml to report all of my classes defined by targets if I call test-all, but if i only want to run a few targets my Junit report only show the last class ran.

To explain further I have two targets in my build.xml "runAll" and "runTest". When i execute the runAll target I get all my classes to show up in the Junit report. When I run multiple targets using runTest my junit reports only show the last class ran.

THIS WORKS AND REPORTS ALL THE CLASSES:

ant test-all

THIS DOESNT AND ONLY REPORTS THE LAST CLASS:

ant testClass1 testClass2 testClass3

here is a snippet of what i am running in my build xml for runAll (this one works):

<target name="runAll" depends="clean,compile, compileTests">
    <taskdef resource="festjunittasks" classpathref="classpath" />

    <mkdir dir="${report.dir}"/>
    <mkdir dir="${results.dir}"/>
    <mkdir dir="${htmlresults.dir}"/>
    <!-- <mkdir dir="${iphone.dir}"/> -->

      <junit forkmode="perTest" printsummary="yes" haltonfailure="no" haltonerror="no" maxmemory="4096m">



        <classpath>
            <path refid="classpath"/>
        </classpath>

        <formatter classname="org.fest.swing.juni开发者_开发百科t.ant.ScreenshotOnFailureResultFormatter" extension=".xml" />

        <batchtest fork="yes" todir="${results.dir}">
            <fileset dir="${testclasses.dir}" includes="**/*Test*.class" />
        </batchtest>
    </junit>

    <festreport todir="${report.dir}">
        <classpath refid="classpath" />
        <fileset dir="${results.dir}">
          <include name="TEST-*.xml" />
        </fileset>
        <report format="frames" todir="${htmlresults.dir}/html" />
      </festreport>
    <copy todir="${history.dir}">
        <fileset dir="${html.dir}"/>
        </copy>


</target >

Here is snippet for my runTest (this one reports only the last class ran):

<target name="runTest" depends="clean,compile, compileTests">
    <taskdef resource="festjunittasks" classpathref="classpath" />
    <mkdir dir="${report.dir}"/>
    <mkdir dir="${results.dir}"/>
    <mkdir dir="${htmlresults.dir}"/>
    <!-- <mkdir dir="${iphone.dir}"/> -->

    <junit forkmode="perTest" printsummary="yes" haltonfailure="no" haltonerror="no" maxmemory="4096m">

        <classpath>
            <path refid="classpath"/>
        </classpath>

        <formatter classname="org.fest.swing.junit.ant.ScreenshotOnFailureResultFormatter" extension=".xml" />

        <batchtest fork="yes" todir="${results.dir}">
            <fileset dir="${testclasses.dir}" includes="**/${test.to.run}" />
        </batchtest>
    </junit>

    <festreport todir="${report.dir}">
        <classpath refid="classpath" />
        <fileset dir="${results.dir}">
          <include name="TEST-*.xml" />
        </fileset>
        <report format="frames" todir="${htmlresults.dir}/html" />
    </festreport>
    <copy todir="${history.dir}">
        <fileset dir="${html.dir}"/>
    </copy>

</target >

thanks in advance


It looks like runTest is being called in a loop within your build. If this is the case, can you change it to create a single fileset with all the tests you want to run and run them at once? This is the easiest way because junitreport (and presumably festreport) expect the xml output from one run.

If you can't run the tests together, the alternative is to run an XML transform to merge the XML output before reporting. Building a single fileset should be easier though.


The problem you are facing is that when you run your first test class and junit creates an html report, junit usually places the following html files in the directory of your choice in your case it would be '${htmlresults.dir}/html':

/com
all-tests.html
allclasses-frame.html
alltests-errors.html
alltests-fails.html
index.html
overview-frame.html
overview-summary.html
stylesheet.css

When you run your second test, the same html files names are created for the second class and stored in the same dir ('${htmlresults.dir}/html'). What happens is that the html files for the first class are overwritten with the second class' html file names since the html file names are constant. Looking at the build.xml snippet, the easiest thing you can do is go to your runTest target and replace the festreport node to this one:

NEW festreoprt NODE for runTest target

<festreport todir="${report.dir}"> 
<classpath refid="classpath" />
<fileset dir="${results.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${htmlresults.dir}/html/${test.to.run}" />
</festreport>

OLD festreoprt NODE for runTest target

<festreport todir="${report.dir}">
<classpath refid="classpath" />
<fileset dir="${results.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${htmlresults.dir}/html" />
</festreport>

The change I made is super simple.

All I did was tell junit target testRun to create a folder named after the class that was just run,

denoted by "${htmlresults.dir}/html/${test.to.run}".

Once that folder is created, it stores the html report files in the folder with the specified class name. When the next consecutive target is executed, junit will run the target, create a new folder named after the class that is being run and then store the html files in the class folder.

You will never run into the html file overwrite issue after that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜