Testng生成的測試報告亂碼解決辦法 &&以Ant方式運行testng框架報 2 字節的 UTF-8 序列的字節 2 無效解決辦法

 Testng生成的測試報告亂碼解決辦法 &&以Ant方式運行testng框架報 2 字節的 UTF-8 序列的字節 2 無效解決辦法html

亂碼是程序編碼不統一,好比Java源代碼是utf-8,編譯是gbk,這時會亂碼。java

若是源代碼utf-8,編譯utf-8,默認會生成gbk格式的報告,ant配置testng標籤里加<jvmarg value="-Dfile.encoding=UTF-8"/>express

具體build文件配置以下:框架

<?xml version="1.0" encoding="GBK"?>
<project name="Demo" default="run" basedir=".">
    <property name="testng.dir" value="D:\java\workspaces\DailyPaper"/>  
    <property name="testng.output.dir" value="D:\java\workspaces\DailyPaper\test-output"/> 
    <path id="run.classpath">
        <fileset dir="jar">
            <include name="testng\*.jar"></include>
		    <include name="poi-3.15\*.jar"></include>
		    <include name="poi-3.15\lib\*.jar"></include>
		    <include name="poi-3.15\ooxml-lib\*.jar"></include>
        	<include name="selenium-2.40.0\*.jar"></include>
        	<include name="selenium-2.40.0\libs\*.jar"></include>
        </fileset>
    </path>
    <path id="test.lib.classpath">
        <fileset dir="lib">
    		<include name="*.jar"></include>
    	</fileset>
    </path>
    <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="run.classpath" />   
    <target name="clean">
        <delete dir="bin"/>
    </target>
    <target name="compile" depends="clean">
        <echo message="mkdir"/>
        <mkdir dir="bin"/>
        <javac srcdir="src"  includeantruntime="false"
            debug="on" debuglevel="lines,vars,source"  destdir="bin" encoding="GBK">
            <classpath refid="run.classpath"/>
        </javac>
    </target>
    <path id="runpath"> 
         <path refid="run.classpath"/> 
         <pathelement location="bin"/> 
    </path> 
    <target name="run" depends="compile">
        <testng  classpathref="runpath"  outputDir="test-output">  
            <xmlfileset dir="${basedir}" includes="testng.xml"/>
          <jvmarg value ="-Dfile.encoding=UTF-8" /><!-- 定義生成報告的編碼 --> 
        </testng>
     
     
    	<xslt in="${testng.output.dir}/testng-results.xml" 
    	               style="${testng.output.dir}/testng-results.xsl" 
    	               out="${testng.output.dir}/index2.html">  
    	               <param name="testNgXslt.outputDir" expression="${testng.output.dir}"/>  
    	               <param name="testNgXslt.showRuntimeTotals" expression="true"/>  
    	               <classpath refid="test.lib.classpath"/>  
    	 </xslt>
     </target>
</project>
相關文章
相關標籤/搜索