public class SingleLogTest extends BaseExample { private final String filePath = "file-path.html"; @BeforeClass public void beforeClass() { extent = new ExtentReports(filePath, true); extent.startReporter(ReporterType.DB, "extent.db"); extent.addSystemInfo("Host Name", "Anshoo"); } @Test public void passTest() { test = extent.startTest("passTest"); test.log(LogStatus.PASS, "Pass"); Assert.assertEquals(test.getRunStatus(), LogStatus.PASS); } @Test public void intentionalFailure() { test = extent.startTest("intentionalFailure"); test.log(LogStatus.FAIL, "Fail"); Assert.assertEquals(test.getRunStatus(), LogStatus.PASS); } }public abstract class BaseExample { protected ExtentReports extent; protected ExtentTest test; @AfterMethod protected void afterEachTest(ITestResult result) { if (!result.isSuccess()) { test.log(LogStatus.FAIL, result.getThrowable()); } extent.endTest(test); extent.flush(); } @AfterSuite protected void afterSuite() { extent.close(); } }
这里说明一下是因为Testng里面有Assert,而这个Assert的结果是无法直接输送到report里的,所以要用到@AfterMethod来获取到每次执行的@Test中的结果来人为的把这个结果人为输送到report中去。
贴一下后生成的结果,感觉还是不错的,之后继续尝试着修改这个jar来符合我们自己想要的样式。