使用extentreports美化报告
2017-09-14 09:19
309 查看
无意之间在整理testng 报告输出的文档时,发现一个美化testng的报告的插件,感觉确实“漂亮”,但是还不确定是否实用,案例来自官方网站自己添了一些内容,更改了存放路径,本地目前已确定可正常运行,官方网址:http://extentreports.com/documentation/version-2/
1.配置maven依赖
<dependency> <groupId>com.relevantcodes</groupId> <artifactId>extentreports</artifactId> <version>2.40.2</version> </dependency>
2.创建一个测试类,我是mytest
自己添加了5个测试方法,3个正确,2个错误
查看展示效果
demo代码
package com.test.appuimtest; import org.apache.tools.ant.util.facade.FacadeTaskHelper; import org.testng.Assert; import org.testng.ITestResult; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus; import until.publicmethod; public class mytest { public class SingleLogTest extends BaseExample { @Test public void passTest() { test = extent.startTest("passTest"); test.log(LogStatus.PASS, "Pass"); Assert.assertEquals(test.getRunStatus(), LogStatus.PASS); } @Test public void intentionalFailure() throws Exception { test = extent.startTest("intentionalFailure"); throw new Exception("intentional failure"); } @Test public void Mytest1(){ test = extent.startTest("Mytest1"); Assert.assertTrue(true); } @Test public void Mytest2(){ test = extent.startTest("Mytest2"); Assert.assertTrue(true); } @Test public void Mytest3(){ test = extent.startTest("Mytest2"); Assert.assertTrue(false); } } public static class ExtentManager { private static ExtentReports extent; public synchronized static ExtentReports getReporter(String filePath) { if (extent == null) { extent = new ExtentReports(filePath, true); extent .addSystemInfo("Host Name", "Anshoo") .addSystemInfo("Environment", "QA"); } return extent; } } public abstract class BaseExample { protected ExtentReports extent; protected ExtentTest test; final String filePath = "d:\\Extent.html"; //这里需要更改创建的存放路径 @AfterMethod protected void afterMethod(ITestResult result) { if (result.getStatus() == ITestResult.FAILURE) { test.log(LogStatus.FAIL, result.getThrowable()); } else if (result.getStatus() == ITestResult.SKIP) { test.log(LogStatus.SKIP, "Test skipped " + result.getThrowable()); } else { test.log(LogStatus.PASS, "Test passed"); } extent.endTest(test); extent.flush(); } @BeforeSuite public void beforeSuite() { extent = ExtentManager.getReporter(filePath); } @AfterSuite protected void afterSuite() { extent.close(); } } }
在继续补充,发现在报告下面还可以增加图片和视频,添加出来的效果如下
相关文章推荐
- 使用extentreports美化testng报告2,增加监听
- 使用TestNG-xslt美化测试报告
- 使用TestNG-xslt美化测试报告
- 使用TestNG-xslt+ant来美化selenium测试报告
- 使用django设置将错误报告发送到指定邮箱
- MFC使用Skin++外观美化
- 使用Tcmalloc的性能测试结果报告,比malloc有大幅度提高
- Ubuntu 中文字体美化方案大全 (5): 使用苹果字体
- FastDFS使用总结报告(1)——FastDFS概述
- 使用Visual Studio.Net,系统报告“automation服务器不能创建对象”错误。解决之道运行:regsvr32 scrrun.dll 就可以了。
- 山东大学Java程序设计课程实验报告5设计和使用类
- 使用SkinMagic Toolkit美化界面
- 使用SkinMagic Toolkit美化界面
- 使用Flash彻底美化你的程序
- 如何优雅地使用Vim?(美化篇)
- 关于syslog的测试使用报告
- 使用VCS生成覆盖率报告
- 使用AWR生成一条sql的执行统计报告
- 学以致用——Excel连接Oracle生成iKB报告——Part1(使用VBA从数据库提取汇总数据)
- 免费版企业级杀毒软件mcafee使用报告。