利用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/ ...
随机推荐
- linux 块设备驱动(四)——简单的sbull实例
#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> # ...
- asp.net core 初探 二
今天用@宇内流云大大的jexus 体验一下生产环境的发布,运行. 生产环境: centos 7 jexus 5.8.1 独立版 包含了mono (mono安装真心痛苦……) 开发环境就是昨天的Ubun ...
- align="absmiddle" 图片的中间上下对齐
align=absmiddle表示图像的中间与同一行中最大元素的中间对齐 AbsBottom 图像的下边缘与同一行中最大元素的下边缘对齐.AbsMiddle 图像的中间与同一行中最大元素的中间对齐.B ...
- Ajax技术实现页面无刷新跳转
Ajax实现无刷新显示新的页面 <!DOCTYPE html> <html> <head> <script src="/jquery/jquery- ...
- quick-cocos2d-x教程3:程序框架内文件夹分析之docs文件夹
如今我们分析框架中的docs文件夹.看看这个文档文件夹中,究竟放了那些对我们实用的东西. docs文件夹分析 UPGRADE_TO_2_2_3.md 就是讲升级的变化.详细说明:quick-cocos ...
- Eclipse中连接Sql Sever2008 -----转自Yogurshine
Eclipse中连接Sql Sever2008 -----转自Yogurshine 一 SQl Sever服务器配置 1我之前已经安装好SQL Sever 2008R2.(注意:安装一遍未成功时,一定 ...
- UITextInputMode类的使用
转载请注明:http://blog.sina.com.cn/s/blog_69081e060100v7ad.html UITextInputMode大家看了是不是有些陌生呢?这个类是在4.2之后才 ...
- Codeforces Round #105 (Div. 2) E. Porcelain —— DP(背包问题)
题目链接:http://codeforces.com/problemset/problem/148/E E. Porcelain time limit per test 1 second memory ...
- 基于BASYS2的VHDL程序——交通灯(状态机版)
请尊重作者版权,转载注明源地址:http://www.cnblogs.com/connorzx/p/3694618.html 使用了状态机,增加了可读性和用户体验. library IEEE; use ...
- Eclipse jar打包详解
通过Eclipse下的演示工程,介绍如何打包这样的项目:要导出的类里边用到了别的jar包. 方法/步骤 1. Eclipse下的演示工程结构如下图所示,其中Task.java是当前工程运行的M ...