ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: JUnit BatchTest
Date Wed, 23 Oct 2002 16:09:49 GMT
Sorry, I can't. It's not a single class, but something which uses other
in-house tools. I can tell you though that it's was inspired by this article
http://www.javaworld.com/javaworld/jw-12-2000/jw-1221-junit_p.html (the last
part of it), which we used almost as-is for a while. DynamicTestSuite is a
re-write of it, which adds classname filtering using patterns similarly to
Ant's patterns (to make it faster, by not doing reflection on all classes). 

It's not great, because not integrated to Ant, and duplicates some of Ant's
features, but it does a fine job overall.

Here's the structure of the class though, were you to decide writing your
own. --DD

public class DynamicTestSuite {

  private DynamicTestSuite() {} // prevent instantiation

  /**
   * The method called by the JUnit framework.
   *
   * @return a JUnit test suite of all the tests that matched
   *         the search criteria
   */
  public static Test suite() {
    final TestSuite suite = new TestSuite();

    ClassPathScanner scanner = null;
    if (SEARCHPATH == null) {
      ClassLoader loader = DynamicTestSuite.class.getClassLoader();
      scanner = new ClassPathScanner(loader);
    }
    else {
      URL[] urls = getURLs(SEARCHPATH);
      scanner = new ClassPathScanner(urls);
    }

    ClassFilter filter1 = new ClassnameFilter(INCLUDES, EXCLUDES);
    ClassFilter filter2 = new TestTypeAndConfigFilter(TYPE, CONFIG);
    scanner.setFilter(new ClassFilter.AND(filter1, filter2));

    final int[] i = {0}; // counter
    scanner.scan(new ClassPathScanner.ClassProcessor() {
      public void process(String classname) {
        try {
          Class clazz = Class.forName(classname);
          // Try classname#suite() first ...
          Test test = suite(clazz);
          if (test != null) {
            suite.addTest(test);
          }
          else {
            // ... then TestSuite#addTestSuite!
            suite.addTestSuite(clazz);
          }
          ++i[0];
        }
        catch (ClassNotFoundException e) { ... }
      }
    });

    return suite;
  }
}

-----Original Message-----
From: Marina Harrell [mailto:Marina.Harrell@sas.com] 
Sent: Wednesday, October 23, 2002 10:40 AM
To: Ant Users List
Subject: RE: JUnit BatchTest

Can you share that DynamicTestSuite code? It would be very useful.

-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com]
Sent: Wednesday, October 23, 2002 11:31 AM
To: 'Ant Users List'
Subject: RE: JUnit BatchTest


No, it is not AFAIK. It relies on files on disk, and cannot deal with files
(classes) inside a JAR. We do not use <batchtest>, but have written our own
'DynamicTestSuite' that finds tests based on similar pattern criteria (plus
additional ones) as <batchtest>, but takes a classpath-like searchpath
(which defaults to the classpath) which can include dirs and/or JARs.

Many such JUnit 'smart' test suite exist in the wild. --DD

-----Original Message-----
From: Tim Sheridan [mailto:tsheridan@intersectsoft.com] 
Sent: Wednesday, October 23, 2002 10:27 AM
To: 'Ant Users List'
Subject: JUnit BatchTest

I am compiling all our test code to a single JAR file of JUnit test cases.
Is there a way the nested <batchtest> tag in the JUnit task can take just a
JAR file? The following code runs the test cases just fine, but I would be
prefer to simply specify a single JAR file. Is it possible? Suggestions?
Thanks, Tim.

    <target name="run.ut">
        <mkdir dir="${ut.result.path}\summary"/>
        <mkdir dir="${ut.result.path}\reports"/>

        <junit fork="yes" maxmemory="256m" showoutput="true"
printsummary="yes">
            <classpath refid="test.code.path"/>
            <formatter type="xml"/>
            <batchtest fork="yes" todir="${ut.result.path}\reports">
                <fileset dir="${output.path}">
                    <include name="**/ut/*.class"/>
                </fileset>
            </batchtest>
        </junit>

        <junitreport todir="${ut.result.path}\reports">
            <fileset dir="${ut.result.path}\reports">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${ut.result.path}\summary"/>
        </junitreport>
    </target>

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

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


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

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


Mime
View raw message