2011-09-26 37 views
8

Tôi vừa tích hợp Cobertura vào kịch bản xây dựng Ant của mình và tôi tự hỏi nếu tôi đã làm nó một cách chính xác vì nó đã làm chậm đáng kể thời gian cần thiết để chạy thử nghiệm đơn vị.Đơn vị thử nghiệm chậm với Cobertura

Đây là một mẫu giao diện điều khiển đầu ra:

... 
[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. 
... 

Dường tanh rằng sau mỗi lần chạy thử Cobertura nói:

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

Đây là đơn vị kiểm tra công việc của tôi từ xây dựng Ant của tôi kịch bản:

<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> 

Cài đặt và đầu ra của tôi có đúng không? Có bình thường đối với các bài kiểm tra đơn vị mất 2,234 giây khi chạy một mình và khi chạy trong kịch bản xây dựng với Cobertura mất 3 phút?

+0

Tôi không thấy vấn đề là gì (ngoài sử dụng Ant :-P), nhưng loại này chậm trễ chắc chắn là không bình thường. –

+0

Tôi lấy nó, bạn có một công cụ ưa thích khác hơn là Ant? Bạn muốn giới thiệu gì? –

+0

maven và gradle là cả hai cải tiến rất lớn so với kiến. thêm cobertura vào một dự án maven là tầm thường. –

Trả lời

8

Từ cobertura-anttask reference:

Vì lý do này cùng, nếu bạn đang sử dụng kiến ​​1.6.2 hoặc cao hơn thì bạn có thể muốn bộ forkmode = "một lần" Điều này sẽ gây ra chỉ có một JVM để được bắt đầu cho tất cả các thử nghiệm JUnit của bạn và sẽ giảm chi phí của Cobertura đọc/ghi tệp dữ liệu bảo hiểm mỗi lần JVM bắt đầu/dừng.

(Nhấn mạnh là của tôi).

+1

hoạt động hoàn hảo, cảm ơn bạn! –

Các vấn đề liên quan