开发者

Ant, JUnit, and a TestSuite

So I'm setting up automatic regression testing with JUnit, and right now the build script is set up to call a TestSuite, which packs a bunch of different tests into a TestSuite and returns it.

buildfile:

<target name="test-perform-check" depends="test-compile">
        <junit printsummary="yes" fork="yes" haltonfailure="no">
            <classpath path ="${mypath}"  />
            <jvmarg value="-Djava.ext.dirs=${extstar};${extpathextended};" />
                    <jvmarg value="-Dmipav=${mipav};" />
            <sysproperty key="mipav" value="${mipav}"/>
           <formatter type="xml"/>
           <formatter type="plain" usefile="false"/>
           <test name="test.JTest"/>
        </junit>
    </target>

JTest.java:

 class JTest extends TestSuite {

    public static Test suite () {
        // set up a bunch of stuff
        TestSuite suite = new TestSuite();
        suite.addTest(new VolumeCompare());
        suite.addTest(new VolumeCompare());
        suite.addTest(new VolumeCompare());
        suite.addTest(new FileExistence());
        // do some other stuff
        return suite;
    }
}

Output:

[junit] Testcase开发者_高级运维: null took 0.002 sec
[junit]     FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit] 
[junit] Testcase: null took 0 sec
[junit]     FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit] 
[junit] Testcase: null took 0.002 sec
[junit]     FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit] 
[junit] Testcase: null took 0 sec
[junit]     FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit] 
[junit] Test test.JTest FAILED

My question is - what do I need to change in the buildscript to make ant run the tests properly?

Edit:

VolumeCompare.java:

public class VolumeCompare extends TestCase {
    public VolumeCompare (...) {
        // ctor
    }
    @Test
    public void testVolume () {
        // this print statement is never reached
        System.out.println("testing volume");
        // compare volumes here
    }
}


From the junit task documentation, I think the test attribute has to be used with a class that contains a single Test (rather than a Suite). Maybe you can use a pattern to ask ant to run every test in a given package, like this :

  <batchtest fork="yes" todir="${reports.tests}">
   <fileset dir="${src.tests}">
     <include name="**/*Test*.java"/>
     <exclude name="**/AllTests.java"/>
   </fileset>
  </batchtest>


When using a TestSuite you add test cases to your suite one testcase at a time, your syntax should look more like this:

suite.addTest(new VolumeCompare("testCase1"));
suite.addTest(new VolumeCompare("testCase2"));
suite.addTest(new VolumeCompare("testCase3"));

Basically you aren't passing the name of a test to run and so it tries to run "null" and fails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜