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();
}
}
這里說(shuō)明一下是因?yàn)門estng里面有Assert,而這個(gè)Assert的結(jié)果是無(wú)法直接輸送到report里的,所以要用到@AfterMethod來(lái)獲取到每次執(zhí)行的@Test中的結(jié)果來(lái)人為的把這個(gè)結(jié)果人為輸送到report中去。
貼一下后生成的結(jié)果,感覺(jué)還是不錯(cuò)的,之后繼續(xù)嘗試著修改這個(gè)jar來(lái)符合我們自己想要的樣式。
