Section 5.3. Testing in Batches


5.3. Testing in Batches

When you're working with JUnit, you can set up test suites, which run multiple tests, by extending the TestSuite class:

import junit.framework.TestCase; import junit.framework.TestSuite;         .         .         . public class NewSuite extends TestSuite  {     static public Test testSuite( )      {         TestSuite suite = new TestSuite( );         suite.addTestSuite(Project.class);          suite.addTestSuite(Connector.class);         suite.addTestSuite(DataHandler.class);         return suite;     } }

When you're using JUnit from Ant, it's easier to use batch testing with the nested batchtest task. This task lets you specify whole filesets to test using the fileset type, and the results will be merged into a report. Here's how to use batchtest:

    <target name="test6" depends="compile">         <junit printsummary="yes" haltonfailure="yes">             <formatter type="brief" usefile="true"/>             <classpath path="."/>              <batchtest todir="${results}">                 <fileset dir="." includes="**/Project.class"/>             </batchtest>         </junit>     </target>

In this case, the fileset only contains a single file (there's only one file to test in this chapter's example), but you can include as multiple files in your nested fileset element:

    <target name="test6" depends="compile">         <junit printsummary="yes" haltonfailure="yes">             <formatter type="brief" usefile="true"/>             <classpath path="."/>              <batchtest todir="${results}">                 <fileset dir="${build}">                    <include name="**/*Test.class"/>                    <include name="**/*Gold.class"/>                    <exclude name="**/*Beta.class"/>                 </fileset>             </batchtest>         </junit>     </target>



    Ant. The Definitive Guide
    Ant: The Definitive Guide, 2nd Edition
    ISBN: 0596006098
    EAN: 2147483647
    Year: 2003
    Pages: 115
    Authors: Steve Holzner

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net