利用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/ ...
随机推荐
- fedora delete openJDK
博客分类: linux 由于Fedora系统安装的时候会自带OpenJDK,安装完系统后 java -version 会显示 [root@localhost bin]# java -versio ...
- LeetCode(88)题解-- Merge Sorted Array
https://leetcode.com/problems/merge-sorted-array/ 题目: Given two sorted integer arrays nums1 and nums ...
- hdu1427 速算24点
</pre><pre> //#pragma comment(linker, "/STACK:102400000,102400000") //HEAD #in ...
- ABAP 实现Excel 粘贴复制
"设置需要复制的区域 CLEAR gv_range. gs_ole2-row1 = . gs_ole2-col1 = . gs_ole2-row2 = . gs_ole2-col2 = . ...
- HTTP1.1学习笔记 -- RFC2616
本人跟web无缘,从来没有想去学http,现在看来,学学也是有益无害,总会要用着点滴. RFC见这里: https://www.ietf.org/rfc/rfc2616.txt 0. URI格式 ht ...
- Understand .sync in Vue
Preface The first time I met .sync modifier, I didn't know it very well. So, I seldom use that. Toda ...
- HDU2586 How far away? —— 倍增LCA
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 How far away ? Time Limit: 2000/1000 MS (Java/Ot ...
- 用HTML5 Canvas为Web图形创建特效
HTML5 Canvas 将使用像素在屏幕上绘制图形图像. 本节演示了五种用于操作像素以创建摄影特效的 Canvas 技术. 您可使用这些技术来生成独具特色的图像,为您的网站.博客.视频游戏画面.广告 ...
- PHP上传文件时,文件过大$_FILES为空
在php中判断上传文件的大小,但是文件一但过大,print_r($_FILES);的值就变为null了,有时候大家会遇到这么一个问题,上传小文件时,PHP能正常获取到,但是文件一超过8M就变为空了,我 ...
- linux应用之tomcat的安装及配置(centos)
CentOS 6.6下安装配置Tomcat环境 [日期:2015-08-25] 来源:Linux社区 作者:tae44 [字体:大 中 小] 实验系统:CentOS 6.6_x86_64 实验前 ...