2010-09-16 40 views
2

我們今天的build.xml有許多編譯和運行單元測試的目標。 build.xml引用了許多相對於自身的屬性文件。當在同一臺機器上完成構建和測試時,所有這些工作都很好。如何將junit測試分發到另一臺機器

構建get_jar和任何測試輸入文件到build_home(另一臺機器)非常簡單。如何在新位置上運行junit?我應該創建小的build.xml文件來運行測試嗎? (無法動態創建ant build.xml)任何解決方案?

(GridGain是可能的解決辦法沒試過呢。)

編輯:模式的細節,爲什麼這更復雜:源代碼是圍繞3G,做ClearCase的更新和建造花費相當長的時間(40分)對抗junit測試的實際測試時間 - 60分鐘。我們有很多機器來運行測試 - 在所有不可能的系統上加載Clearcase。

回答

2

我理解你的問題,因爲你只想在另一臺機器上運行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> 
+0

您幾乎可以說我想要的是不可能對build.xmls進行更改。接受的答案,因爲它有足夠的解釋關於如何構建構建文件。謝謝! – Jayan 2010-09-26 16:29:37

1

嘗試克魯斯控制。這是將構建和單元測試卸載到另一臺機器的好方法。

+0

由於單獨的文件。巡航控制如何運行測試?我們使用哈德森,所以我可以使用類似的技術。 – Jayan 2010-09-16 12:57:15

+0

Hudwon同樣出色。爲什麼不配置它作爲構建的一部分運行測試? – duffymo 2010-09-16 13:33:58

+0

我們這樣做。它工作正常。不同的是在哈德森上構建,在另一個上運行測試。我現在看到的方式是讓junit在另一個ant文件中運行代碼,如junit.xml,並複製「jars」和「testdata」。使用junit.xml運行測試(來自JoseK) – Jayan 2010-09-17 05:37:01

相關問題