You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Marcel Stör <ma...@frightanic.com> on 2005/08/30 13:40:58 UTC

[Junit] How to handle TestSuites correctly

Hi all,

We're having major difficulties using the junit/junitreport targets with
JUnit TestSuites.

Usually, the junit target produces an XML file for each test class and
junitreport produces a superb report based on those files. In our case,
however, we end up with one XML file only since our TestSuite (which of
course contains several test cases) is treated as one single test case.
Accordingly only one HTML report is produced. It lists all tests (i.e. test
methods), but we loose the reference to the test class that defines the test
method. Here is a screenshot:
http://www.frightanic.com/ant_junitreport_suite.gif

Any ideas how to get a report showing the test class as well?

Here is the ANT code:

<junit haltonerror="false" showoutput="true" errorProperty="test.failed"
failureProperty="test.failed">
 <classpath refid="compile.classpath" />
 <formatter type="xml" usefile="true" />
 <batchtest fork="yes" todir="${reports.tests}">
  <fileset dir="${src.tests}">
   <include name="**/AllTests.java" />
  </fileset>
 </batchtest>
</junit>

<junitreport todir="${reports.tests}">
 <fileset dir="${reports.tests}">
  <include name="TEST-*.xml" />
 </fileset>
 <report format="frames" todir="${reports.tests}/html/" />
</junitreport>

<fail if="test.failed">
 Unit tests failed.  Check log or reports for details.
${reports.tests}html/index.html
</fail>


Here is our JUnit Java code:

    public static TestSuite suite() {
        final TestSuite allTests = new TestSuite("All Tests");
        allTests.addTestSuite(myFirstTest.class);
        allTests.addTestSuite(mySecondTest.class);
        ...

        return allTests;
    }



-- 
Marcel Stör
http://www.frightanic.com


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: [Junit] How to handle TestSuites correctly

Posted by Marcel Stör <ma...@frightanic.com>.
Joe Schmetzer wrote:
> On Tue, 2005-08-30 at 13:40 +0200, Marcel Stör wrote:
>> Hi all,
>>
>> We're having major difficulties using the junit/junitreport targets
>> with JUnit TestSuites.
>>
>> Usually, the junit target produces an XML file for each test class
>> and junitreport produces a superb report based on those files. In
>> our case, however, we end up with one XML file only since our
>> TestSuite (which of course contains several test cases) is treated
>> as one single test case. Accordingly only one HTML report is
>> produced. It lists all tests (i.e. test methods), but we loose the
>> reference to the test class that defines the test method. Here is a
>> screenshot: http://www.frightanic.com/ant_junitreport_suite.gif
>>
>> Any ideas how to get a report showing the test class as well?
>
> You want to exclude the combined suite from the batchtest, and include
> all the individual tests instead. This will generate an XML file for
> each test case, and the report will show each individual classname.
>
> In your example, change the line reading
>
>    <include name="**/AllTests.java" />
>
> to look like
>
>    <include name="**/*Test.java" />


Oh, sorry, I forgot to mention something....This is how used it up to now.
However, since each test will run individually, they take forever to finish.
Somehow junit forces each test to have its own application context (?).
Singletons kept in memory are lost once a new test class is loaded. If we
pack everything into one suite we can get around that.

--
Marcel Stör
http://www.frightanic.com


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: [Junit] How to handle TestSuites correctly

Posted by Joe Schmetzer <jo...@exubero.com>.
On Tue, 2005-08-30 at 13:40 +0200, Marcel Stör wrote:
> Hi all,
> 
> We're having major difficulties using the junit/junitreport targets with
> JUnit TestSuites.
> 
> Usually, the junit target produces an XML file for each test class and
> junitreport produces a superb report based on those files. In our case,
> however, we end up with one XML file only since our TestSuite (which of
> course contains several test cases) is treated as one single test case.
> Accordingly only one HTML report is produced. It lists all tests (i.e. test
> methods), but we loose the reference to the test class that defines the test
> method. Here is a screenshot:
> http://www.frightanic.com/ant_junitreport_suite.gif
> 
> Any ideas how to get a report showing the test class as well?

You want to exclude the combined suite from the batchtest, and include
all the individual tests instead. This will generate an XML file for
each test case, and the report will show each individual classname.

In your example, change the line reading

   <include name="**/AllTests.java" />

to look like

   <include name="**/*Test.java" />

This assumes that all your individual test cases use the same naming convention.

-- 
Joe Schmetzer .:. Renaissance Developer .:. http://www.exubero.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org