下载安卓APP箭头
箭头给我发消息

客服QQ:3315713922

如何在eclipse中使用Ant执行JUnit

作者:课课家教育     来源: http://www.kokojia.com点击数:765发布时间: 2016-01-29 18:38:44

标签: java开发java语言java eclipse使用

大神带你学编程,欢迎选课

  建立工程:

  在ecliPSe中建立一个java project.

如何在eclipse中使用Ant执行JUnit_java开发_java语言_课课家

  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

  3 < project name ="project" default ="junit" >

  4 < property name ="run.classpath" value ="bin" >

  5 < property name ="run.srcpath" value ="src" >

  6 < property name ="test.srcpath" value ="src" >

  7 < property name ="test.report" value ="report" >

  8 < property name ="lib.dir" value ="lib" />

  9 < path id ="compile.path" >

  10 < fileset dir ="${lib.dir}" >

  11 < include name ="**/*.jar" />

  12

  13

  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

  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

  28

  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

  34

  35

  36

  37

  运行:

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

  结果:

  控制台有输出结果,例如:

  Buildfile: C:\\Documents and Settings\\qianwang\\My Documents\\D\\SMPWorkspace\\AntTest\\build.xml

  compile:

  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 sec

  BUILD SUCCESSFUL

  Total time: 19 seconds

  结果文件中,会指出运行了哪些testcase(指出被测试的方法名test**).

  如果有failures/errors,异常的详细信息也会输出在这里.

赞(0)
踩(0)
分享到:
华为认证网络工程师 HCIE直播课视频教程