范围报告版本 - 3.0 语言 - Java 和 TestNG 类
我有一堂课——ExtentManager.java
package framewrk;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
public class ExtentManager {
private static ExtentReports extent;
private static ExtentTest test;
private static ExtentHtmlReporter htmlReporter;
private static String filePath = "./extentreport.html";
public static ExtentReports GetExtent(){
extent = new ExtentReports();
htmlReporter = new ExtentHtmlReporter(filePath);
// make the charts visible on report open
htmlReporter.config().setChartVisibilityOnOpen(true);
// report title
String documentTitle = prop.getProperty("documentTitle", "aventstack - Extent");
htmlReporter.config().setDocumentTitle(documentTitle);
}
public static ExtentTest createTest(String name, String description){
test = extent.createTest(name, description);
return test;
}
public static ExtentTest createTest(String name){
test = extent.createTest(name, "");
return test;
}
}
和 2 个 testNG 类如下 TC1.java
package framewrk;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
public class TC1 {
static ExtentReports extent;
static ExtentTest test;
@BeforeClass
public void setup(){
extent = ExtentManager.GetExtent();
}
@Test
public void OpenUT(){
test = extent.createTest("Testing how fail works");
test.log(Status.INFO, "fail check started");
test.fail("Test fail");
}
@AfterClass
public void tear()
{
extent.flush();
}
}
TC2.java
package framewrk;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
public class TC2 {
static ExtentReports extent;
static ExtentTest test;
@BeforeClass
public void setup(){
extent = ExtentManager.GetExtent();
}
@Test
public void OpenUT(){
test = extent.createTest("Testing how pass works");
test.log(Status.INFO, "pass check started");
test.pass("Passed");
}
@AfterClass
public void tear()
{
extent.flush();
}
}
如果运行这两个测试用例,我只得到最后一个测试用例结果,对于第一个测试用例结果,它不会显示在范围报告中。请注意,范围报告 3.0 没有附加参数。如何在范围报告上获取所有测试用例结果?