利用ant 和 Junit 生成测试报告
我们除了使用java来直接运行junit之外,我们还可以使用junit提供的junit task与ant结合来运行。
涉及的几个主要的ant task如下:
|
<junit>,定义一个junit task |
运行Junit需要jakarta-ant-1.4-optional.jar和Junit.jar包,因为这两个包用于支持ant task--<junit>的,所以不能在build.xml文件中加载,需要将他们放到ANT_HOME中的lib目录中
junit.jar下载地址:http://pan.baidu.com/s/1hsbg464
jakarta-ant-1.4-optional.jar下载地址:http://pan.baidu.com/s/1hsjTXhM
完成上面的配置之后,开始编写build.xml,并将其放置在项目的根目录下。
<?xml version="1.0" encoding="utf-8"?> <project name="project" default="junit">
<property name="run.classpath" value="bin"/>
<property name="run.srcpath" value="src"/>
<property name="test.xml" value="xml"/>
<property name="test.report" value="report"/>
<property name="lib.dir" value="lib"/> <target name="init">
<delete dir="${test.report}"/>
<mkdir dir="${test.report}"/>
<delete dir="${test.xml}"/>
<mkdir dir="${test.xml}"/>
</target> <target name="compile" depends="init">
<javac destdir="${run.classpath}" srcdir="${run.srcpath}" classpathref="compile.path" includeantruntime="on"/>
</target> <!--Junit task-->
<target name="junit" depends="compile">
<junit printsummary="false">
<classpath path="${run.classpath}"/>
<formatter type="xml"/>
<batchtest todir="${test.xml}">
<fileset dir="${run.classpath}">
<!--运行${run.classpath}下所有和"**/*.class"匹配的用例-->
<include name="**/*.class"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${test.xml}">
<fileset dir="${test.xml}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.report}"/>
</junitreport>
</target>
</project>
编写junit case例子,注意需要继承TestCase
package com.test.report;
import static org.junit.Assert.*;
import org.junit.Test;
import junit.framework.TestCase;
public class ANTTest extends TestCase {
int i = 0;
Boolean b = false;
@Test
public void test001() {
if (i == 0) {
b = true;
} else {
assertTrue("i is 0", b);
}
}
@Test
public void test002() {
if (i == 1) {
b = true;
} else {
assertTrue("i is 0", b);
}
}
}
进入项目根目录,执行ant命令

进入根目录下的report目录,找到index.html文件

打开index.html查看测试结果

参考:
http://www.cnblogs.com/puresoul/p/4201565.html
http://blog.csdn.net/tochal/article/details/12560151
如果在运行testcase时需要依赖第三方包,那么build.xml需要被改成下面的内容
<?xml version="1.0" encoding="utf-8"?> <project name="project" default="junit">
<property name="run.classpath" value="bin"/>
<property name="run.srcpath" value="src"/>
<property name="test.xml" value="xml"/>
<property name="test.report" value="report"/>
<property name="lib.dir" value="lib"/> <path id="compile.path">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${run.classpath}"/>
</path> <target name="init">
<delete dir="${test.report}"/>
<mkdir dir="${test.report}"/>
<delete dir="${test.xml}"/>
<mkdir dir="${test.xml}"/>
</target> <target name="compile" depends="init">
<javac destdir="${run.classpath}" srcdir="${run.srcpath}" classpathref="compile.path" includeantruntime="on"/>
</target> <!--Junit task-->
<target name="junit" depends="compile">
<junit printsummary="true">
<classpath refid="compile.path"/>
<formatter type="xml"/>
<!--<test name="cn.com.vp4.hup.testcase.TestCase_AudioFocus"/> -->
<batchtest todir="${test.xml}">
<fileset dir="${run.classpath}">
<include name="**/*AudioFocus.class"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${test.xml}">
<fileset dir="${test.xml}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.report}"/>
</junitreport>
</target>
</project>
利用ant 和 Junit 生成测试报告的更多相关文章
- ant+jmeter 自动生成测试报告
1,把Jmeter根目录/extras 下的ant-jmeter-xxx.jar拷贝到ant根目录/lib下 2, 修改Jmeter的bin目录下jmeter.properties文件的配置:jmet ...
- 【Junit_Ant】使用Eclipse自带的Junit和Ant,生成测试报告
使用Eclipse自带的Junit和Ant,生成测试报告 1.点击要测试的工程,右击,选择Export 2.在弹出的页面里,点击General,选择Ant Buildfiles,点击Next 3.在下 ...
- Linux下利用Ant调用Jmeter脚本生成HTML测试报告
今天我们学习如何利用Ant调用Jmeter脚本,并将生成的 jtl 文件转换为 HTML 格式的测试报告. 准备工作 需要在Linux上提前安装好 JDK. Jmeter 和 Ant. 1,JDK(可 ...
- linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
原创,转载请注明:http://www.cnblogs.com/ycxyyzw/p/4555328.html 之前写过一篇<windows下Android利用ant自动编译.修改配置文件.批量 ...
- UI测试后生成测试报告,利用shell脚本上传svn
ui测试后生成测试报告,把报告保存在某一个固定路径 shell脚本把这个报告上传 #!/bin/bash -ile #svn下载文件 #svn checkout http://svn.xxx.com/ ...
- 利用Maven把项目生成jar包供其他项目使用
每当搭建框架时,第一步就是为系统整理一个接一个的jar包.用多了就开始深思,如何把自己的项目也整成jar包,供他人使用呢? 近期一直在看徐晓斌所著:<Maven实战>.因自己学识不够,只是 ...
- 利用 Ant 和 Eclipse 有效地提高部署工作效率
读者定位为具有 Java 和 Ant 使用经验的开发人员. 读者可以学习到如何使用 Ant 解决一些多用户开发环境中,根据不同的目标环境编译成不同部署包的问题. 工作场景 现在有一个 web 项目,是 ...
- 整理的Unity导出安卓工程利用ANT进行多渠道批量打包APK
Unity导出的安卓工程利用ant进行多渠道循环批量打包 一:设置JAVA环境变量 做android开发的配置这个是基础. win7 下配置java环境变量,下面是链接 http://www.cnbl ...
- Ubuntu环境下利用ant编译nutch2.2.1 & 配置nutch2.2.1
/×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...
随机推荐
- iOS移动开发周报-第20期
iOS移动开发周报-第20期iOS移动开发周报-第20期 [摘要]:本期iOS移动开发周报带来如下内容:iOS 通知中心扩展制作入门,iOS APP可执行文件的组成,objc非主流代码技巧等. 教程 ...
- forEach for for in for of性能问题
var arr = new Array(1000); console.time('forEach'); arr.forEach(data => { }); console.timeEnd('fo ...
- Html调用 QQ接口
<A href="tencent://message/?uin=1805843351&Site=有事Q我&Menu=yes"> <img styl ...
- jquery 备忘笔记
1.选择器 a.查询所有以某字符串开头的元素 $("input[id^='dgItem_txt']") b.获取一组单选按钮中选中的值 $("input[name='it ...
- Collection of Boot Sector Formats for ISO 9660 Images
http://bazaar.launchpad.net/~libburnia-team/libisofs/scdbackup/view/head:/doc/boot_sectors.txt Colle ...
- 清理yum 缓存
两条命令 yum clean all 以及 rm -rf /var/cache/yum/* 如何有效的清理yum缓存 - CSDN博客 https://blog.csdn.net/nsrainbow/ ...
- mac 中安装redis 以及 安装php-redis扩展过程详细记录
1. 通过homebrew 安装 redis sodu brew install redis 2. 安装后执行开启redis,采用默认配置, 默认配置只有本地(127.0.0.1)可以访问.需要远程访 ...
- HLS切片机
参考: 1,linux下搭建生成HLS所需的.ts和.m3u8文件http://www.cnblogs.com/mystory/archive/2013/04/07/3006200.html2,iPh ...
- 【智能无线小车系列八】在树莓派上使用USB网卡
在这个腾“云”驾“物”(云:云计算,物:物联网)的时代,什么都可以没有,就是不能没有网络,树莓派也离不开它.本章节将详细介绍如何将树莓派接入互联网,因为有一些后期将要使用到的小软件需要联网进行下载和安 ...
- 利用ES6中的Proxy和Reflect 实现简单的双向数据绑定
利用ES6中的Proxy (代理) 和 Reflect 实现一个简单的双向数据绑定demo. 好像vue3也把 obj.defineProperty() 换成了Proxy+Reflect. 话不多说 ...