我理解你的問題,因爲你只想在另一臺機器上運行Junit測試,而無需實際構建它?您可以將下面的行作爲Cruise控件的構建腳本,也可能是Hudson的構建腳本
如果您通過ant使用該任務,則遵循與標準構建相同的原則。您可以從源代碼管理中檢出所有目標機器的代碼。
將所有根目錄外部化爲build.properties。這些屬性必須像這樣在每臺機器上設置。
#Overall Project Name
project.name=myapp
# Top Level Root directory of the new working project
toplevel.project.dir=D:/proj/eComm
# Root directory of the source code
root.project.dir=D:/proj/eComm/Construction
# JDK home directory
jdk.home=C:/jdk1.5.0_11
build.properties也會有一些相對於上面定義的靜態屬性。這些不需要任何用戶在任何本地機器上進行更改。
ear.dist.dir = ${root.project.dir}/target
src.dir = ${root.project.dir}/src
test.src.dir = ${root.project.dir}/test
確保您的build.xml僅指通過這些屬性的任何進一步的子目錄沒有任何硬編碼值。
我的junit是在由
<import file="${root.project.dir.buildscripts.dir}/junit.xml"/>
導入的build.xml和junit.xml的某些部分被示出在下面
<target name="run.junit" depends="clean.junit, junit.info, prepare.junit"
description="Compiles and runs all JUnit Tests in the 'test' directory and produces a report of all failures">
<junit printsummary="yes" fork="true" haltonfailure="no" showoutput="yes" maxmemory="512m">
<jvmarg line="${junit.jvm.arg}"/>
<classpath>
<fileset dir="${src.dir}">
<include name="**/*.*"/>
</fileset>
<fileset dir="${ear.dist.dir}/build/classes">
<include name="**/*.*"/>
</fileset>
<pathelement path="${test.run.path}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="true" todir="${ear.dist.dir}/build/junit">
<fileset dir="${test.src.dir}" includes="${test.pattern.include}"/>
</batchtest>
</junit>
</target>
您幾乎可以說我想要的是不可能對build.xmls進行更改。接受的答案,因爲它有足夠的解釋關於如何構建構建文件。謝謝! – Jayan 2010-09-26 16:29:37