2

I have an ant task set up like so:

<target name="unit-test" description="unit tests" depends="compile-tests">
   <mkdir dir="${build}/test"/>
   <mkdir dir="${build}/test/raw"/>
   <mkdir dir="${build}/test/reports"/>

   <!-- set up scratch database for tests -->
   <mkdir dir="${build.dbTest}" />

  <junit printsummary="yes" haltonfailure="no" maxmemory="512m" >
   <classpath>
     <pathelement path="${java.class.path}"/>
     <pathelement path="${build.classes}"/>
     <pathelement path="${build.test-classes}"/>
     <fileset dir="lib" includes="*.jar"/>
     <fileset dir="lib-test" includes="*.jar"/>
   </classpath>
   <formatter type="xml"/>
   <sysproperty key="derby.system.home" value="${build.dbTest}" />
   <batchtest fork="yes" todir="${build}/test/raw">
     <fileset dir="${src.test}">
       <include name="**/*Test.java"/>
     </fileset>
   </batchtest>
 </junit>
  <junitreport todir="${build}/test">
   <fileset dir="${build}/test/raw"/>
   <report todir="${build}/test/reports"/>
 </junitreport>
</target>

Which works pretty well for running all my tests, but running all my tests really slows down my TDD Fail-Pass-Refactor groove. My full test suite takes about six minutes to run, which is way too long for quick response changes during TDD, especially since most of the time I only care about results from one test. The work flow I'd like to have would be

  1. create test for new feature/bug
  2. run only the new test (or at most only the test class I just modified)
  3. write some code
  4. iterate 2-3 until the new tests are passing
  5. run full set of tests to make sure nothing else broke
  6. plug any broken test into the 2-3 cycle above and repeat full cycle
  7. when all tests pass, declare victory.

TestNG seems to have capability for grouping tests, which seems ideal (I could have a "TDD" group for the tests I'm currently working with. Changing that when I start working on something is an acceptable level of manual configuration here), but I don't want to switch test frameworks unless I absolutely have to. Is there any way to do something similar, or another way to achieve my desired work flow, using JUnit?

Michael Easter
  • 23,733
  • 7
  • 76
  • 107
Mark Tozzi
  • 10,353
  • 5
  • 22
  • 30

1 Answers1

4

I use in my scripts instead of

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

the snippet

<include name="${test}"/>

and set the property test to **/*Test.java earlier in the script. Now I can start ant, setting the property to a different value:

ant test -Dtest=**/*AcceptanceTests.java
Mnementh
  • 50,487
  • 48
  • 148
  • 202