2012-04-15 47 views
14

Vấn đề: Các xét nghiệm là (dường như) không được thực hiệnAnt, chạy tất cả JUnit thử nghiệm

Bước 1: Soạn nguồn để bin

<target name="compile" depends="init" description="compile the source "> 
    <javac srcdir="${src}" destdir="${build}" includeantruntime="true" nowarn="yes" debug="true" /> 
    <javac srcdir="${src}" destdir="${bin}" includeantruntime="true" nowarn="yes" debug="true" /> 
</target> 

Bước 2: Biên soạn các xét nghiệm để bin

<target name="compileTest" depends="compile" description="compile jUnit Test cases "> 
    <javac srcdir="${test-dir}" destdir="${bin}" includeantruntime="true" nowarn="yes" debug="true" /> 
</target> 

Bước 3: Tìm Test.class (es) và chạy chúng

<target name="test" depends="compileTest"> 
     <junit> 
      <formatter type="plain" usefile="false" /> 
      <formatter type="plain" /> 
      <batchtest> 
       <fileset dir="${bin}" includes="**/Test*.class" /> 
      </batchtest> 
     </junit> 
    </target> 

Output:

Buildfile: /Users/xx/Documents/repositories/app/build.xml 
clean: 
    [delete] Deleting directory /Users/xx/Documents/repositories/app/build 
    [delete] Deleting directory /Users/xx/Documents/repositories/app/bin 
init: 
    [mkdir] Created dir: /Users/xx/Documents/repositories/app/build 
    [mkdir] Created dir: /Users/xx/Documents/repositories/app/bin 
compile: 
    [javac] Compiling 145 source files to /Users/xx/Documents/repositories/app/build 
    [javac] Compiling 145 source files to /Users/xx/Documents/repositories/app/bin 
compileTest: 
    [javac] Compiling 24 source files to /Users/xx/Documents/repositories/app/bin 
test: 
dist: 
    [delete] Deleting: /Users/xx/Documents/repositories/app/dist/app.jar 
     [jar] Building jar: /Users/xx/Documents/repositories/app/dist/app.jar 
    [copy] Copying 1 file to /Users/xx/Documents/repositories/app/dist 
    [delete] Deleting: /Users/xx/Documents/repositories/app/dist/app.war 
     [war] Building war: /Users/xx/Documents/repositories/app/dist/app.war 
    [copy] Copying 1 file to /Users/xx/Documents/repositories/app/dist 
BUILD SUCCESSFUL 
Total time: 5 seconds 

am i thiếu gì xin vui lòng?

Trả lời

22

Tôi tin rằng bạn có thể sử dụng batchtest bên junit nhiệm vụ:

<target name="test" depends="compileTest"> 
    <junit> 
    <classpath> 
     <pathelement location="bin" />  
     <pathelement location="lib/junit-4.10.jar"/> 
    </classpath>  
    <batchtest> 
     <fileset dir="${test}"> 
      <include name="**/*Test*" /> 
     </fileset> 
    </batchtest> 
    <formatter type="brief" usefile="false"/> 
    </junit> 
</target> 

Note sau:

  • Trong fileset dir="${test}" phải trỏ đến thư mục nguồn cho các bài kiểm tra.
  • Trong include name="**/*Test*" bạn nên không phải chỉ định .class mở rộng; nó phải là .java hoặc không có gì.
  • Bạn cần thêm thư mục đầu ra kiểm tra làm "classpath" cho phần tử tác vụ junit.

Tôi đã thử nghiệm với một dự án đơn giản và có cùng cấu hình tôi nhận được kết quả ngắn gọn. Tôi đã sử dụng Apache Ant 1.7.1.

+0

Điều này dường như chỉ chạy thử nghiệm từ gói đầu tiên trong test-src. Ngoài ra, có cách nào để giảm báo cáo cho một cái gì đó như "Ran 500 thử nghiệm, 0 lỗi 0 lỗi"? – JAM

+0

Tuy nhiên, không có bản tóm tắt nào xuất hiện – JAM

+0

Đã cập nhật câu hỏi của tôi để bao gồm toàn bộ tập lệnh ANT – JAM

1

Sử dụng "batchtest" như thế này:

<batchtest> 
    <fileset dir="${tst-dir}" includes="**/Test*.class" /> 
    </batchtest> 

Ví dụ hiện nay trên here.

EDIT:

Đối với bản tóm tắt in thấy ant junit task does not report detailthis

Lưu ý rằng bạn không còn cần các thuộc tính printsummary="yes"showoutput="true" trong nhiệm vụ JUnit. Trình định dạng đang xử lý đầu ra ngay bây giờ.

<target name="test" depends="compileTest"> 
    <junit> 
     <formatter type="plain" usefile="false" /> <!-- to screen --> 
     <formatter type="plain" /> <!-- to file --> 

     <batchtest> 
      <fileset dir="${bin}" includes="**/Test*.class" /> 
     </batchtest> 
    </junit> 
</target> 
+0

Thêm bên trong thẻ junit trước thẻ batchtest –

+0

@JAM xem EDIT ở trên –

+0

Phải. Tôi đã có điều đó :) – JAM

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