TestNG+Ant 测试报告美化
来源:互联网 发布:最好的网络机顶盒 编辑:程序博客网 时间:2024/05/29 15:28
TestNG本身的测试报告很不美观,我们可以下载testng-xslt,加入其中的jar包去进行美化。该效果比reportNG还要美观。
1.下载testng-xslt(如testng-xslt-1.1.2版本)
其中lib下的saxon-8.7.jar 是用来美化report的jar。
2.新建JAVA项目,在项目下新建一个lib文件夹,用来加入jar文件;新建testoutput文件夹,在其中加入testng-results.xsl (路径:testng-xslt-1.1.2-master\src\main\resources)用来承再生成美化的测试报告。
3.lib里面加入需要的jar文件, 并引用。
4.TestNGSimpleTest.java
- import org.testng.annotations.Test;
- import static org.testng.Assert.assertEquals;
- public class TestNGSimpleTest {
- @Test
- public void testAdd() {
- String str = "TestNG is working fine";
- assertEquals("TestNG is working fine", str);
- }
- }
import org.testng.annotations.Test;import static org.testng.Assert.assertEquals;public class TestNGSimpleTest {@Testpublic void testAdd() {String str = "TestNG is working fine";assertEquals("TestNG is working fine", str);}}
5.src下建testng.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
- <suite name="Suite1">
- <test name="test1">
- <classes>
- <class name="TestNGSimpleTest"/>
- </classes>
- </test>
- </suite>
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" ><suite name="Suite1"> <test name="test1"> <classes> <class name="TestNGSimpleTest"/> </classes> </test></suite>
6.可以通过File-export-Ant的方式,将项目转化为Ant项目,会自动生成build.xml,然后修改代码为:
- <project name="TestNGTest" default="testoutput" basedir=".">
- <!-- Define <testng> task -->
- <taskdef name="testng" classname="org.testng.TestNGAntTask">
- <classpath>
- <pathelement location="lib/testng-6.8.jar" />
- </classpath>
- </taskdef>
- <property name="testoutputdir" location="testoutput" />
- <property name="srcdir" location="src" />
- <property name="libdir" location="lib" />
- <property name="full-compile" value="true" />
- <property name="basedir" value="D:/workspace/TestNGSimple/" />
- <path id="classpath.test">
- <fileset dir="${libdir}">
- <include name="**/*.jar" />
- </fileset>
- <pathelement location="${testoutputdir}" />
- <pathelement location="${srcdir}" />
- </path>
- <target name="clean">
- <delete dir="${basedir}/bin" />
- </target>
- <target name="compile" depends="clean">
- <mkdir dir="${basedir}/bin" />
- <javac srcdir="${srcdir}" encoding="UTF-8" destdir="${basedir}/bin" verbose="${full-compile}" classpathref="classpath.test" includeantruntime="off" debug="on" debuglevel="lines,vars,source" />
- </target>
- <path id="classes">
- <fileset dir="${libdir}" includes="*jar"/>
- <fileset dir="${libdir}" includes="*zip"/>
- <pathelement location="${basedir}/bin/"/>
- </path>
- <target name="runtest" depends="compile">
- <testng outputdir="${testoutputdir}" classpathref="classes" delegateCommandSystemProperties="true">
- <xmlfileset dir="${srcdir}" includes="testng.xml" />
- </testng>
- </target>
- <target name="testoutput" depends="runtest">
- <xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html ">
- <param name="testNgXslt.outputDir" expression="D:/workspace/TestNGSimple/testoutput/" />
- <classpath refid="classpath.test" />
- </xslt>
- </target>
- </project>
<project name="TestNGTest" default="testoutput" basedir="."><!-- Define <testng> task --><taskdef name="testng" classname="org.testng.TestNGAntTask"><classpath><pathelement location="lib/testng-6.8.jar" /></classpath></taskdef><property name="testoutputdir" location="testoutput" /><property name="srcdir" location="src" /><property name="libdir" location="lib" /><property name="full-compile" value="true" /><property name="basedir" value="D:/workspace/TestNGSimple/" /><path id="classpath.test"><fileset dir="${libdir}"><include name="**/*.jar" /></fileset><pathelement location="${testoutputdir}" /><pathelement location="${srcdir}" /></path><target name="clean"><delete dir="${basedir}/bin" /></target><target name="compile" depends="clean"><mkdir dir="${basedir}/bin" /><javac srcdir="${srcdir}" encoding="UTF-8" destdir="${basedir}/bin" verbose="${full-compile}" classpathref="classpath.test" includeantruntime="off" debug="on" debuglevel="lines,vars,source" /></target><path id="classes"><fileset dir="${libdir}" includes="*jar"/><fileset dir="${libdir}" includes="*zip"/><pathelement location="${basedir}/bin/"/></path><target name="runtest" depends="compile"><testng outputdir="${testoutputdir}" classpathref="classes" delegateCommandSystemProperties="true"><xmlfileset dir="${srcdir}" includes="testng.xml" /></testng></target><target name="testoutput" depends="runtest"><xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html "><param name="testNgXslt.outputDir" expression="D:/workspace/TestNGSimple/testoutput/" /><classpath refid="classpath.test" /></xslt></target></project>
7. 右键 build.xml 文件,Run as -- Ant build
8. testoutput中 生成测试美化后的报告
注意:
1.
- <project name="TestNGTest" default="testoutput" basedir=".">
<project name="TestNGTest" default="testoutput" basedir=".">default=“testoutput”,如果不需要美化的报告,则改为runtest
2.注意classes 的配置,然后引入到runtest的配置中,否则报找不到class的异常。
- <path id="classes">
- <fileset dir="${libdir}" includes="*jar"/>
- <fileset dir="${libdir}" includes="*zip"/>
- <pathelement location="${basedir}/bin/"/>
- </path>
<path id="classes"><fileset dir="${libdir}" includes="*jar"/><fileset dir="${libdir}" includes="*zip"/><pathelement location="${basedir}/bin/"/></path>
- <target name="runtest" depends="compile">
- <testng outputdir="${testoutputdir}" classpathref="classes" delegateCommandSystemProperties="true">
- <xmlfileset dir="${srcdir}" includes="testng.xml" />
- </testng>
- </target>
<target name="runtest" depends="compile"> <testng outputdir="${testoutputdir}" classpathref="classes" delegateCommandSystemProperties="true"> <xmlfileset dir="${srcdir}" includes="testng.xml" /> </testng> </target>
3.testng-results.xml在路径(testng-xslt-1.1.2-master\test\single)下
- <target name="testoutput" depends="runtest">
- <xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html ">
- <param name="testNgXslt.outputDir" expression="D:/workspace/TestNGSimple/testoutput/" />
- <classpath refid="classpath.test" />
- </xslt>
- </target>
<target name="testoutput" depends="runtest"><xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html "><param name="testNgXslt.outputDir" expression="D:/workspace/TestNGSimple/testoutput/" /><classpath refid="classpath.test" /></xslt></target>
0 0
- TestNG+Ant 测试报告美化
- TestNG+Ant 测试报告美化
- 使用TestNG-xslt+ant来美化selenium测试报告
- TestNg测试报告美化
- TestNG测试报告美化
- testNG测试报告美化
- TestNG测试报告美化
- 使用TestNG-xslt美化测试报告
- 使用TestNG-xslt美化测试报告
- TestNG入门笔记[6]:TestNG-xslt 美化测试报告
- ant+TestNG-xslt生成selenium测试报告
- ant构建testNG测试输出测试报告
- ant+testng-xslt生成selenium测试报告
- 使用ant运行testng使用testng-results.xsl美化结果
- 使用ant运行testng的testng.xml并且使用testng-results.xsl美化结果
- 使用ant运行testng的testng.xml并且使用testng-results.xsl美化结果
- 测试报告生成 TestNG-xslt
- testNG之测试报告
- 网站构建技术了解
- [教程]解决真机调试时Eclipse DDMS上打不开/data目录的问题
- 计算两点间的距离_Java_杭电ACM2001
- AFG与AWG的比较
- 内存管理
- TestNG+Ant 测试报告美化
- iOS进行单元测试OCUnit+xctool
- windows Eclipse远程连接linux hadoop2.3.0伪分布式
- 一次mysql数据库迁移的过程记录
- LNUX 介绍各个文件目录
- 如何用Python写一个贪吃蛇AI
- Android开发(28) Fragment生命周期
- javascript基础
- Use gitk to understand git – merge and rebase