我想創建一個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),這使得有可能通過螞蟻運行特定的「類別」的測試。 –