Ant 告诉我我的 Junit 测试成功了,但实际上却没有成功
我有以下 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
I have the following build.xml file
<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>
and I have the following test class just to test out the build
package com.mmz.mvc.test;
import junit.framework.*;
public class MemberDAOTest extends TestCase
{
public void test1() {
assertTrue("Test didn't work",false);
}
}
Obviously this test is supposed to fail, but its not. Can anybody tell me why I am getting the following output. Also, if there is something you see wrong, then please let me know if I can improve my build script, I am new to writing any build files.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确认 Ant 运行最新版本的 MemberDAOTest 的简单方法:
添加方法
test2()
,以查看 Ant 是否运行test2()
。Easy way to confirm Ant runs your latest version of MemberDAOTest:
Add method
test2()
, to see if Ant runstest2()
or not.