-
大小: 1.25MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-11-04
- 语言: Java
- 标签: testNG-xslt. testng reportng
资源简介
用TestNG测试后,自动会生成html的测试报告,不过相信大家都有感觉,自动生成的测试报告太难看了,所以我们又用了ReportNG来美化它。在 这里给大家再介绍一下比reportNG还要稍稍美观一点的reporting tool: testNG-xslt.
解压后把saxon-8.7.jar放到project的lib目录下
3. 然后再把/src/main/resources/testng-results.xsl放到你的测试目录里,或是随便一个什么目录下
4. 创建一个简单的build.xml, 如下:
最后执行ant transform就可以了,之后在output目录下就可以看到一个index.html文件,打开它就是测试报告了。
代码片段和文件信息
package org.testng.xslt.mavenplugin;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Locale;
/**
* @author Cosmin Marginean Apr 1 2008
* @goal xslt
*/
public class TestNgXsltMojo extends AbstractMavenReport {
/**
* @parameter expression=“${project}“
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter default-value=“${project.reporting.outputDirectory}/testng-xslt“
* @required
*/
private String outputDir;
/**
* @parameter
*/
private String cssFile;
/**
* The name of the report to use
*
* @parameter default-value=“TestNG XSLT Results“
*/
private String reporttitle;
/**
* Indicates whether to sort the test cases links in the left frame
*
* @parameter default-value=““
*/
private boolean sortTestCaselinks;
/**
* The description of the report
*
* @parameter
*/
private String reportDescription;
/**
* The directory where SureFire has stored its results.
*
* @parameter default-value=“${project.build.directory}/surefire-reports“
*/
private String surefireReportDirectory;
/**
* @parameter
*/
private boolean showRuntimeTotals;
/**
* @parameter
*/
private String testDetailsFilter;
protected void executeReport(Locale locale) throws MavenReportException {
String testNgResultsxml = getTestNgResultsxmlPath();
getLog().info(“TestNG XSLT is processing file ‘“ + testNgResultsxml + “‘“);
if (!new File(testNgResultsxml).exists()) {
getLog().warn(“File ‘testng-results.xml‘ could not be found. No reports will be generated by TestNG XSLT“);
return;
}
try {
Thread.currentThread().setContextClassLoader(net.sf.saxon.TransformerFactoryImpl.class.getClassLoader());
System.setProperty(“javax.xml.transform.TransformerFactory“ “net.sf.saxon.TransformerFactoryImpl“);
TransformerFactory factory = TransformerFactory.newInstance();
String outputDir = getHtmlOutputDir();
getLog().info(“TestNG XSLT is generating HTML in directory ‘“ + outputDir + “‘“);
new File(outputDir).mkdirs();
StreamSource inputSource = new StreamSource(new File(testNgResultsxml));
Transformer transformer = factory.newTransformer(new StreamS
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2008-06-11 21:06 src\
目录 0 2008-06-11 21:06 src\main\
目录 0 2008-06-11 21:06 src\main\java\
目录 0 2008-06-11 21:06 src\main\java\org\
目录 0 2008-06-11 21:06 src\main\java\org\testng\
目录 0 2008-06-11 21:06 src\main\java\org\testng\xslt\
目录 0 2008-06-11 21:06 src\main\java\org\testng\xslt\mavenplugin\
目录 0 2008-06-11 21:06 src\main\resources\
文件 6654 2009-05-20 00:08 src\main\java\org\testng\xslt\mavenplugin\TestNgXsltMojo.java
文件 58790 2009-05-20 00:00 src\main\resources\testng-results.xsl
目录 0 2008-06-11 21:06 lib\
目录 0 2008-06-11 21:06 lib\saxon-license\
目录 0 2008-06-11 21:06 lib\saxon-license\intro_files\
目录 0 2008-06-11 21:06 lib\saxon-license\third-party-components_files\
文件 3268315 2008-06-11 21:06 lib\saxon-8.7.jar
文件 16106 2008-06-11 21:06 lib\saxon-license\intro.html
文件 4083 2008-06-11 21:06 lib\saxon-license\intro_files\saxondocs.css
文件 8603 2008-06-11 21:06 lib\saxon-license\intro_files\saxonica_logo.gif
文件 43 2008-06-11 21:06 lib\saxon-license\intro_files\spacer.gif
文件 43 2008-06-11 21:06 lib\saxon-license\intro_files\text_blue_dot.gif
文件 33631 2008-06-11 21:06 lib\saxon-license\third-party-components.html
文件 4083 2008-06-11 21:06 lib\saxon-license\third-party-components_files\saxondocs.css
文件 8603 2008-06-11 21:06 lib\saxon-license\third-party-components_files\saxonica_logo.gif
文件 43 2008-06-11 21:06 lib\saxon-license\third-party-components_files\spacer.gif
文件 43 2008-06-11 21:06 lib\saxon-license\third-party-components_files\text_blue_dot.gif
目录 0 2008-06-24 20:59 test\
目录 0 2009-05-20 00:20 test\custom-css\
目录 0 2009-05-20 00:20 test\maven\
目录 0 2008-06-13 21:58 test\maven\src\
目录 0 2008-06-13 22:05 test\maven\src\main\
目录 0 2008-06-13 22:05 test\maven\src\main\java\
............此处省略55个文件信息
评论
共有 条评论