2012-07-11 42 views
0

我正在嘗試針對一系列RMI接口/實現編寫單元測試,並依靠Ant + Junit來促進這些測試。主要問題是我需要在我的Junit任務開始時啓動rmiregistry,並在執行結束時關閉,無論是失敗,錯誤還是成功。 Ant腳本:Ant執行任意程序並在junit任務結束時終止

<project> 
    <target name="test"> 
     <javac srcdir="Test/src" destdir="Test/bin" /> 
     <junit fork="true" printsummary="true"> 
      <batchtest> 
      <fileset dir="Test/test"> 
       <include name="**/*Test.*"/> 
      </fileset> 
      </batchtest> 
     </junit> 
    </target> 
</project> 
+0

你基本上知道如何啓動和關閉T他註冊表? – oers 2012-07-11 16:18:12

+0

@oers yes從命令行啓動rmiregistry。要關閉註冊表,我將終止該過程。 – Woot4Moo 2012-07-11 16:20:24

回答

1

基本上,只要設置haltonerror="false"failonerror="false「爲junit任務
這樣junit不會失敗,由於測試的開始和停止通過exec task做我以前的taskkill這裏。殺rmiregistry.exe。

<exec executable="start"> <--your start command here --> 
    <arg value="rmiregistry"/> 
</exec> 
<junit fork="true" printsummary="true" haltonerror="false" failonerror="false" errorproperty="juniterrors" failureproperty="junitfailures"> 
    ... 
</junit> 
<exec executable="taskkill"> <--your shutdown command here --> 
    <arg value="/IM"/> 
    <arg value="rmiregistry.exe"/> 
</exec> 
<fail if="juniterrors"/> <!-- ant can fail now, if desired --> 
<fail if="junitfailures"/> 

另一種選擇是使用try/catch from ant-contrib,但我不認爲這是需要在這裏。