我想创建一个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 [junit] jar:file:/usr/local/Cellar/ant/1.9.7/libexec/lib/ant.jar!/org/apache/tools/ant/Project.class [junit]和jar:文件:/Users/arnab/work/my_project/webapp/WEB-INF/lib/ant.jar /组织/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
类别中的所有课程?我错过了什么吗?
我已经添加了一个答案给你的链接[问题](http://stackoverflow.com/a/42000110/1183010),这使得有可能通过蚂蚁运行特定的“类别”的测试。 –