• 使用ant运行testng的testng.xml并且使用testng-results.xsl美化结果


    先看build.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <project basedir="." default="testoutput" name="automation test"> <!--默认使用testoutput任务-->
        <property name="base.dir" value="E:/eclipse/workplace/testng"/><!--项目根目录-->
    
    <property name="testng.output.dir" value="${base.dir}/result"/><!--配置结果输出地址-->
    
    <property name="lib.dir" value="${base.dir}/lib"/><!--设置其他jar包目录-->
    
    <property name="testng.file" value="${base.dir}/testng.xml"/> <!--调用的testng用例执行xml文件,这里是文件名-->
     <property name="testdir" location="test" /> <!--设置编译的2进制文件目录-->
    
     <taskdef resource="testngtasks" classpath="${lib.dir}/testng.jar"/><!--导入testng的jar包-->
    
    <target name="clean"> <!--清除之前的2进制文件-->
    
    <delete dir="${testdir}"/>
    
    </target>
    
    <target name="compile" depends="clean">
    
    <mkdir dir="${testdir}"/><!--新建2进制文件存放目录-->
    <mkdir dir="result"/> <!--新建结果导出目录-->
    
    <javac srcdir="${base.dir}/src" encoding="UTF-8" destdir="${testdir}" classpathref="classes"
    
    includeantruntime="off" debug="on" debuglevel="lines,vars,source"/> </target> <!--编译java程序-->
    
    <path id="classes"> <!--设置jar包相关-->
    <fileset dir="${lib.dir}" includes="*.jar"/>
    <pathelement location="${testdir}"/>
    <pathelement location="${base.dir}/src" />
    </path>
    
    
    <target name="runtest" depends="compile">
    <!--运行testng文件-->
    <!-- 在target里面新建一个testng标签,里面需要设置的属性有:outputdir – 测试结果输出目录;classpathref – 那些自动化测试代码的目标路径,通常就是编译完成以后的那个目标路径,例如xxx/bin;delegateCommandSystemProperties – 接受传递命令行参数作为系统变量,这个设置为true可以在调用Ant的时候通过 -Dfoo=value 把参数传递给TestNG;里面还有一个xmlfileset节点,这个节点就是指定testng.xml文件的目录以及具体文件。 -->
    <testng outputdir="${base.dir}/test-output" 
        classpathref="classes"
         delegateCommandSystemProperties="true">
    
    <xmlfileset dir="${base.dir}" includes="testng.xml"/> <!--在指定路径下,找文件名由testng.file--> 
    </testng> <!--定义的testng.xml文件-->
    
    </target>
        <tstamp>   
            <format property="CURTIME" pattern="yyyyMMdd_HHmmss" locale="us"/>   <!--设置当前时间-->
        </tstamp>   
    <path id= "test.classpath" >
    <fileset dir= "${lib.dir}" includes= "*.jar" />
    </path>
    
    <target name= "testoutput" depends="runtest" >
    <xslt in= "test-output/testng-results.xml" style= "test-output/testng-results.xsl"
    out= "result/${CURTIME}/index.html " >
    <param name= "testNgXslt.outputDir" expression="${base.dir}/result/${CURTIME}/" />
     <param name="testNgXslt.showRuntimeTotals" expression="true"/>
      <param name="testNgXslt.sortTestCaseLinks" expression="true" />
     <param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
    <classpath refid= "test.classpath" />
    </xslt>
    </target>
    </project>

    在eclipse中,他的结构是: 
    project: 

    src(存放源代码) 

    lib(存放jar包) 

    test-output(存放testng的结果的目录) 

    testng.xml(testng的设置) 

    build.xml(ant的设置)

    准备: 
    testng-xslt-1.1.2-master文件下载地址 
    testng.jar文件 下载地址

    操作: 
    1.把testng-xslt-1.1.2-master中libsaxon-8.7.jar放入eclipse 的lib目录下 
    2.把testng-xslt-1.1.2-master中srcmain esources estng-results.xsl放入eclipse 的test-output的文件夹中 
    3.把上面的代码放入build.xml 
    4.点击build.xml右键run: Ant build

  • 相关阅读:
    Hibernate工作原理
    Java jar包查询下载方法
    http状态码(HTTP Status Code)
    Android Broadcast Receiver (广播接收者)
    Android ViewPager组件
    Android Activity属性
    Android XML Drawable
    Android 样式布局
    Android Activity的LaunchMode四种模式
    Android Layout布局
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/8442258.html
Copyright © 2020-2023  润新知