【发布时间】:2016-07-21 08:54:55
【问题描述】:
背景
我正在尝试创建一个 Ant 脚本:
- 编译源文件
- 编译junit测试
- 运行特定类别的 junit 测试
到目前为止,我所做的大部分工作都来自this question。
到目前为止,这是我的 ant 脚本中的内容:
<?xml version="1.0"?>
<project name="junit_tests">
<property name="build-main" location="build/main"/>
<property name="build-test" location="build/main"/>
<property name="src-test" value="java/test" />
<property name="src-com" value="java/com" />
<property name="src-lib" value="webapp/WEB-INF/lib" />
<property name="test-lib" value="java/test/lib" />
<path id="classpath">
<fileset dir="${src-lib}" includes="*.jar"/>
<fileset dir="${test-lib}" includes="*.jar" />
</path>
<path id="classpath.test">
<path refid="classpath"/>
<pathelement location="${build}"/>
</path>
<target name="init">
<mkdir dir="${build-main}" />
<mkdir dir="${build-test}" />
</target>
<target name="compileSrc" depends="init" description="compile src files ">
<javac debug="on" destdir="${build-main}" encoding="UTF-8" fork="true" memorymaximumsize="1024m" includeantruntime="true">
<src path="${src-com}" />
<classpath refid="classpath"/>
</javac>
<javac debug="on" destdir="${build-main}" encoding="UTF-8" fork="true" memorymaximumsize="1024m" includeantruntime="true">
<src path="${src-test}" />
<classpath refid="classpath"/>
</javac>
</target>
<!-- Test and build all files -->
<!-- To run this: use "ant" (default) or "ant run" -->
<target name="run" depends="compileSrc">
<junit printsummary="on" haltonfailure="no" fork="true">
<classpath>
<path refid="classpath.test" />
<pathelement location="${build-test}"/>
</classpath>
<formatter type="xml" />
<batchtest>
<fileset dir="${build-main}" includes="**/NonDBTest.class" />
</batchtest>
</junit>
</target>
</project>
junit 任务的输出
运行: [junit] 警告:在 junit 的路径中检测到多个版本的 ant [junit] jar:file:/usr/local/Cellar/ant/1.9.7/libexec/lib/ant.jar!/org/apache/tools/ant/Project.class [junit] 和 jar:file:/Users/arnab/work/my_project/webapp/WEB-INF/lib/ant.jar!/org/apache/tools/ant/Project.class [junit] 运行 test.NonDBTest [junit] 测试运行:2,失败:0,错误:2,跳过:0,经过时间:0.178 秒
构建成功总时间:37 秒
问题
NonDBTest 这个类别中的测试类总共有 7 个测试,所以 junit 显然没有运行所有这些。
NonDBTest.java 只是一个没有方法的接口,这就是我的测试类的样子
@Category(NonDBTest.class)
public class MyTestClass extends AbstractTestCase{
....
@Test
public void testA(){ ... }
@Test
public void testB(){ ... }
@Test
public void testC(){ ... }
@Test
public void testD(){ ... }
@Test
public void testE(){ ... }
}
问题
我究竟做错了什么?我尝试将NonTestDB 更改为一个类。我已经尝试实现该接口,但到目前为止没有任何效果。如何让 junit 运行 NonTestDB 类别中的所有类?我错过了什么吗?
【问题讨论】:
-
我已经为您的链接 question 添加了一个答案,这使得通过 ant 运行特定
Category的测试成为可能。