我想在我的junit測試中通過ant任務啓動將codecoverage與jacoco集成在一起。由於我的classpath非常長,叉子崩潰,事實上jacoco迫使我岔開我的junit它給了我一些問題。 我正在使用manifestclasspath將我的類路徑添加到jar文件中,將新的jar作爲參數發送給虛擬機,但它不工作。我的測試運行,但他們都返回一個ClassNotFoundException。 這裏有一個關於我如何配置我的螞蟻進程的portin。使用Manifestclasspath來運行junit的Ant ClassNotFoundException
<path refid="bin.classpath"/>
bin.classpath包含我需要放在我的.jar文件中的所有路徑。
<target name="run-unit-tests" depends="init" description="Runs all the unit tests">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="jacocoant.jar" />
</taskdef>
<manifestclasspath property="binjar" jarfile="binManifest.jar">
<classpath refid="bin.classpath" />
</manifestclasspath>
<jar destfile="manifestJars/binManifest.jar">
<manifest>
<attribute name="Class-Path" value="${binjar}" />
</manifest>
</jar>
<jacoco:coverage destfile="results/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<junit fork="true" reloading="false" showoutput="true">
<classpath>
<pathelement path="${projects.dir}/AntProject/manifestJars/binManifest.jar" />
</classpath>
<batchtest todir="${test.data.dir}" fork="true">
<fileset dir="${projects.dir}/ProjectFolder1/src" />
<fileset dir="${projects.dir}/ProjectFolder2/src" />
</batchtest>
</junit>
</jacoco:coverage>
</target>
如果我看一下控制檯日誌運行螞蟻任務,我可以看到我的新.jar文件正在發送時:
-classpath''C:\Users\XXX\Project\AntProject\manifestJars\binManifest.jar;
如果我打開binManifest.jar創建我找到了MANIFEST.MF文件,其所有路徑位於Class-Path屬性中,格式爲:../../Class1/bin ../../Class2/bin ../../ClassN/bin。但由於某些原因,我的所有測試都失敗了,因爲我的類沒有找到。我錯過了什麼?謝謝。
因爲路徑是相對的('../../ Class1/bin'),所以猜測可能是工作目錄不正確。 – Godin
感謝您的回答@Godin。我也這麼想過,但我試過改變我的manifest.mf內容來放絕對路徑或改變我的.jar文件到根文件夾。對於第一種情況,測試會以相同的錯誤崩潰,對於第二種情況,顯示的相對路徑完全相同 –