gpt4 book ai didi

java - 如何在 ExtentReports 中添加跳过的测试用例?

转载 作者:行者123 更新时间:2023-12-02 10:57:01 25 4
gpt4 key购买 nike

我需要将所有跳过的测试用例添加到我的 ExtentReports 中。我怎样才能实现这个目标?

我在我的BaseTest.java中尝试了以下代码:

@AfterMethod
public void afterMethod(Method method)
{
if (result.getStatus() == ITestResult.FAILURE)
{
((ExtentTest) extentTest.getTest()).log(LogStatus.FAIL, result.getThrowable());
}
else
if (result.getStatus() == ITestResult.SKIP)
{
((ExtentTest) extentTest.getTest()).log(LogStatus.SKIP, "Test skipped " + result.getThrowable());
}
else
{
((ExtentTest) extentTest.getTest()).log(LogStatus.PASS, "Test passed");
}

report.endTest(extentTest);
report.flush();
}

最佳答案

尝试实现 ITestListener 和以下方法:

  public interface ITestListener extends ITestNGListener {

void onTestStart(ITestResult result);

public void onTestSuccess(ITestResult result);

public void onTestFailure(ITestResult result);

public void onTestSkipped(ITestResult result);

public void onTestFailedButWithinSuccessPercentage(ITestResult result);

public void onStart(ITestContext context);

public void onFinish(ITestContext context);

}

所以实现看起来像这样:

public class test implements ITestListener {

@Override
public void onTestSkipped(ITestResult result) {
... do Your stuff for skip tests extent report here ...
}

@Override
public void onTestSuccess(ITestResult result) {
... do Your stuff for passed test extent report here ...
}

... and all other methods are automatically implemented, and You don't have to check status, test will automatically enter proper methods.


@Override
public void onStart(ITestContext context){
//init extent reports... on whatever way You do it...
}


@Override
public void onFinish(ITestContext context){
report.endTest(extentTest);
report.flush();
}

}

这对于所有测试都是通用的。

希望这有帮助,

关于java - 如何在 ExtentReports 中添加跳过的测试用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51648318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com