在eclipse中使用Ant執行JUnit

來源:互聯網
上載者:User

建立工程:

在eclipse中建立一個java project.

AntTest
-src
-com.test
-ABS.java
-ABSTest.java (Junit Test Case)
-lib
-build.xml
-JUNIT_HOME/junit.jar
配置:

eclipse->window->preference->ANT->Runtime->Classpath->ANT Home Entry

選擇Add External JAR,加入ECLIPSE_HOME/plugins/org.junit.../junit.jar

build.xml的內容:

1
2 <? xml version="1.0" ?>
3 < project name ="project" default ="junit" >
4 < property name ="run.classpath" value ="bin" ></ property >
5 < property name ="run.srcpath" value ="src" ></ property >
6 < property name ="test.srcpath" value ="src" ></ property >
7 < property name ="test.report" value ="report" ></ property >
8 < property name ="lib.dir" value ="lib" />
9 < path id ="compile.path" >
10 < fileset dir ="${lib.dir}" >
11 < include name ="**/*.jar" />
12 </ fileset >
13 </ path >
14 < target name ="compile" >
15 < javac destdir ="${run.classpath}" srcdir ="${run.srcpath}" classpathref ="compile.path" />
16 < javac destdir ="${run.classpath}" srcdir ="${test.srcpath}" classpathref ="compile.path" />
17 </ target >
18 < target name ="junit" depends ="compile" >
19 < tstamp />
20 < mkdir dir ="${test.report}" />
21 < mkdir dir ="${test.report}/framework-${DSTAMP}-${TSTAMP}" />
22 < junit printsummary ="true" >
23 < classpath >
24 < pathelement path ="${run.classpath}" />
25 < fileset dir ="${lib.dir}" >
26 < include name ="**/*.jar" />
27 </ fileset >
28 </ classpath >
29 < formatter type ="plain" />
30 < batchtest fork ="yes" todir ="${test.report}/framework-${DSTAMP}-${TSTAMP}" >
31 < fileset dir ="${test.srcpath}" >
32 < include name ="**/*Test.java" />
33 </ fileset >
34 </ batchtest >
35 </ junit >
36 </ target >
37 </ project >
運行:

右鍵build.xml->run as "Ant Build".

結果:

控制台有輸出結果,例如:

Buildfile: C:\Documents and Settings\qianwang\My Documents\D\SMPWorkspace\AntTest\build.xmlcompile:junit:    [mkdir] Created dir: C:\Documents and Settings\qianwang\My Documents\D\SMPWorkspace\AntTest\report\framework-20070201-1712    [junit] Running com.test.ABSTest    [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0 secBUILD SUCCESSFULTotal time: 19 seconds

結果檔案中,會指出運行了哪些testcase(指出被測試的方法名test**).

如果有failures/errors,異常的詳細資料也會輸出在這裡.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.