2011-09-26 51 views
8

我最近集成了Cobertura到我的Ant構建腳本中,我在想我是否正確執行它,因爲它顯着減慢了運行單元測試所花費的時間。單元測試與Cobertura緩慢

下面是一個簡單的控制檯輸出:

... 
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.ViewportDeterminingMarkupStrategyTest 
[junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.38 sec 
[junit] Flushing results... 
[junit] Flushing results done 
[junit] Cobertura: Loaded information on 282 classes. 
[junit] Cobertura: Saved information on 282 classes. 
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.VisibleFeatureTypesMarkupInfoTest 
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.434 sec 
[junit] Flushing results... 
[junit] Flushing results done 
[junit] Cobertura: Loaded information on 282 classes. 
[junit] Cobertura: Saved information on 282 classes. 
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.basemap.BasemapByViewportStrategyTest 
[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 2.016 sec 
[junit] Flushing results... 
[junit] Flushing results done 
[junit] Cobertura: Loaded information on 282 classes. 
[junit] Cobertura: Saved information on 282 classes. 
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.basemap.BasemapByZoomLevelAndCenterPointStrategyTest 
[junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 1.853 sec 
[junit] Flushing results... 
[junit] Flushing results done 
[junit] Cobertura: Loaded information on 282 classes. 
[junit] Cobertura: Saved information on 282 classes. 
... 

似乎腥,每個試運行後的Cobertura說:

[junit] Cobertura: Loaded information on 282 classes. 
[junit] Cobertura: Saved information on 282 classes. 
... 

這裏是我的Ant構建腳本我的單元測試任務:

<target name="unit-test" depends="compile-unit-test"> 
    <delete dir="${reports.xml.dir}" /> 
    <delete dir="${reports.html.dir}" /> 
    <mkdir dir="${reports.xml.dir}" /> 
    <mkdir dir="${reports.html.dir}" /> 

    <junit fork="yes" dir="${basedir}" failureProperty="test.failed" printsummary="on"> 
     <!-- 
       Note the classpath order: instrumented classes are before the 
       original (uninstrumented) classes. This is important. 
      --> 
     <classpath location="${instrumented.dir}" /> 
     <classpath refid="test-classpath" /> 

     <formatter type="xml" /> 
     <test name="${testcase}" todir="${reports.xml.dir}" if="testcase" /> 
     <batchtest todir="${reports.xml.dir}" unless="testcase"> 
      <fileset dir="TestSource"> 
       <include name="**/*Test.java" /> 
       <exclude name="**/XmlTest.java" /> 
       <exclude name="**/ElectedOfficialTest.java" /> 
       <exclude name="**/ThematicManagerFixturesTest.java" /> 
      </fileset> 
     </batchtest> 
    </junit> 
</target> 

我的設置和輸出是否正確?如果單獨運行單元測試需要2.234秒,並且在Cobertura的構建腳本中運行需要3分鐘,這是否正常?

+0

我看不出有什麼問題(除了使用Ant :-P),但這種延遲是絕對不正常的。 –

+0

我認爲你有另一個首選的工具,而不是螞蟻?你會推薦什麼? –

+0

maven和gradle都是對ant的巨大改進。向maven項目添加cobertura是微不足道的。 –

回答

8

cobertura-anttask reference

出於相同的原因,如果你使用Ant 1.6.2或更高版本,那麼你 可能要集forkmode =「一次」這將導致只有一個JVM來爲 已開始用於所有JUnit測試,並且每次啓動/停止JVM 時將減少Cobertura讀取/寫入覆蓋率數據文件的開銷。

(重點是我的。)

+1

工作完美,謝謝! –