ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Martin <jeff.mar...@synamic.co.uk>
Subject [PATCH] Pattern based Junit tests
Date Tue, 08 Aug 2000 11:07:06 GMT
This is a patch which adds a new subtask called batchtest to the junit task.
Batchtest allows you to specify a  source and a file name filter to find
test case classes. e.g. <batchtest file="**/test_*.java"
srcdir="${java.src}" /> will find all the test which start with test_ and
the execute them.

Index: src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/
junit/JUnitTask.java,v
retrieving revision 1.4
diff -r1.4 JUnitTask.java
63a64
> import org.apache.tools.ant.DirectoryScanner;
71a73,74
> import java.util.NoSuchElementException;
> import java.util.StringTokenizer;
93a97
>     private Vector batchTests = new Vector();
174a179,281
>     public JUnitBatchTest createBatchTest() {
>         final JUnitBatchTest result = new JUnitBatchTest(project);
> 
>         result.setFork(defaults.getFork());
>         result.setHaltonerror(defaults.getHaltonerror());
>         result.setHaltonfailure(defaults.getHaltonfailure());
>         result.setPrintsummary(defaults.getPrintsummary());
>         result.setPrintxml(defaults.getPrintxml());
> 
>         batchTests.addElement(result);
>         return result;
>     }
> 
>     public final class JUnitBatchTest{
>         private String[] commandLine=null;
>         private boolean fork=false;
>         private boolean haltOnError=false;
>         private boolean haltOnFailure=false;
>         private String srcDir=null;
>         private String outFile=null;
>         private boolean printSummary=false;
>         private boolean printXml=false;
>         private String fileName=null;
> 
>         private Project project=null;
> 
>         public JUnitBatchTest( Project project ){
>             this.project = project;
>         }
> 
>         public final void setCommandline(String[] args) {
>             this.commandLine = args;
>         }
>         public final void setFork(boolean value) {
>             this.fork = value;
>         }
>         public final void setHaltonerror(boolean value) {
>             this.haltOnError = value;
>         }
>         public final void setHaltonfailure(boolean value) {
>             this.haltOnFailure = value;
>         }
>         public final void setSrcdir(String value) {
>             this.srcDir = project.getBaseDir() +
System.getProperty("file.separator") + value;
>         }
>         public final void setFile(String value) {
>             this.fileName = value;
>         }
>         public final void setOutfile(String value) {
>             this.outFile = value;
>         }
>         public final void setPrintsummary(boolean value) {
>             this.printSummary = value;
>         }
>         public final void setPrintxml(boolean value) {
>             this.printXml = value;
>         }
>         public final Enumeration elements(){
>             return new FileList();
>         }
>         public class FileList implements Enumeration{
>             private String files[]=null;
>             private int i=0;
>                 
>             private FileList(){
>                 if(fileName==null)throw new BuildException("The attribute
file on batchtest must be set.");
>                 DirectoryScanner ds = new DirectoryScanner();
>                 ds.setIncludes(new String[]{fileName});
>                 ds.setBasedir(new File(srcDir));
>                 ds.scan();
>                 files = ds.getIncludedFiles();
>             }
>             public final boolean hasMoreElements(){
>                 if(i<files.length)return true;
>                 return false;
>             }
>             public final Object nextElement() throws
NoSuchElementException{
>                 if(hasMoreElements()){
>                     JUnitTest test = new JUnitTest(
>                         fork,
>                         haltOnError,
>                         haltOnFailure,
>                         printSummary,
>                         printXml,
>                         javaToClass(files[i]),
>                         outFile);
>                     i++;
>                     return test;
>                 }
>                 throw new NoSuchElementException();
>             }
>             public final String javaToClass(String fileName){
>                 StringBuffer className=new StringBuffer();
>                 StringTokenizer toke = new StringTokenizer(fileName,
System.getProperty("file.separator"));
>                 while(toke.hasMoreElements()){
>                     className.append(toke.nextToken());
>                     className.append(".");
>                 }
>                 return className.substring(0,className.length()-6);
>             }
>         }
>     }
> 
198a306,312
> 
>         // Expand the batch tests
>         for(Enumeration e = batchTests.elements();e.hasMoreElements();){
>             for(Enumeration ee =
((JUnitBatchTest)e.nextElement()).elements();ee.hasMoreElements();){
>                 tests.addElement(ee.nextElement());
>             }
>         }

Mime
View raw message