我有以下build.xml文件
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="classes"/>
<property name="web.dir" value="war"/>
<property name="test.dir" value="test"/>
<path id="build.classpath">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<!-- servlet API classes: -->
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
<pathelement path="${test.dir}"/>
</path>
<path id="classpath.base"/>
<path id="classpath.test">
<pathelement location="c:/ant/lib/junit.jar" />
<pathelement location="${build.dir}"/>
<pathelement location="${src.dir}"/>
<pathelement location="${test.dir}" />
<pathelement location="classes"/>
<path refid="classpath.base" />
</path>
<target name="build">
<!-- Following two lines creat src and test folders in WEB/INF folders -->
<mkdir dir="${build.dir}"/>
<mkdir dir="${test.dir}"/>
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="build.classpath"/>
</javac>
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true">
<src path="${test.dir}"/>
<classpath refid="build.classpath"/>
</javac>
</target>
<target name="test">
<junit haltonfailure="true" printsummary="yes">
<classpath refid="classpath.test" />
<classpath refid="build.classpath"/>
<formatter type="brief" usefile="false" />
<batchtest fork="yes">
<fileset dir="${test.dir}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
我有以下测试类来测试构建
package com.mmz.mvc.test;
import junit.framework.*;
public class MemberDAOTest extends TestCase
{
public void test1() {
assertTrue("Test didn't work",false);
}
}
显然这个测试应该会失败,但事实并非如此。任何人都可以告诉我为什么我得到以下输出。此外,如果您看到错误的内容,请告诉我是否可以改进构建脚本,我是新编写任何构建文件。
test:
[junit] Running com.mmz.mvc.test.MemberDAOTest
[junit] Testsuite: com.mmz.mvc.test.MemberDAOTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.018 sec
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.018 sec
BUILD SUCCESSFUL
Total time: 1 second
答案 0 :(得分:1)
确认Ant运行最新版本的MemberDAOTest 的简便方法:
添加方法test2()
,以查看Ant是否运行test2()
。