ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ingmar Stein" <st...@xtramind.com>
Subject JUnit task trying to execute inner classes of test classes (+patch)
Date Thu, 28 Jun 2001 12:50:01 GMT
Hi all,

when you run the JUnit task like this:

  <junit printsummary="yes" haltonfailure="no" maxmemory="256m">
   <formatter type="xml"/>
   <batchtest fork="yes" todir="${path.dlogs}/xml">
    <fileset dir="${path.build}">
     <include name="**/*Test*.class"/>
    </fileset>
   </batchtest>
  </junit>

then the task tries to execute all classes that have a "Test" in their name
_including
inner classes_ which might not be TestCases.
This causes JUnit to issue errors although there are none.

If you don't want to upset your fellow programmers, you can use the patch
that
skips inner classes which I have included below.

This function should replace the one in BatchTest.java.

    /**
     * Iterate over all filesets and return the filename of all files
     * that end with <tt>.java</tt> or <tt>.class</tt>. This is to
avoid
     * wrapping a <tt>JUnitTest</tt> over an xml file for example. A
Testcase
     * is obviouslly a java file (compiled or not).
     * @return an array of filenames without their extension. As they should
     * normally be taken from their root, filenames should match their fully
     * qualified class name (If it is not the case it will fail when running
the test).
     * For the class <tt>org/apache/Whatever.class</tt> it will return
<tt>org/apache/Whatever</tt>.
     */
    private String[] getFilenames(){
        Vector v = new Vector();
        final int size = this.filesets.size();
        for (int j=0; j<size; j++) {
            FileSet fs = (FileSet) filesets.elementAt(j);
            DirectoryScanner ds = fs.getDirectoryScanner(project);
            ds.scan();
            String[] f = ds.getIncludedFiles();
            for (int k = 0; k < f.length; k++) {
                String pathname = f[k];
                /* skip inner classes */
  if( pathname.indexOf( "$" ) >= 0 )
                    continue;
                if (pathname.endsWith(".java")) {
                    v.addElement(pathname.substring(0,
pathname.length()-".java".length()));
                } else if (pathname.endsWith(".class")) {
                    v.addElement(pathname.substring(0,
pathname.length()-".class".length()));
                }
            }
        }

        String[] files = new String[v.size()];
        v.copyInto(files);
        return files;
    }


Cheers,

IngmarStein


Mime
View raw message