如何在 ExtentReports 中添加跳过的测试用例?
How can I add skipped test cases in ExtentReports?
我需要将所有跳过的测试用例添加到我的 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();
}
}
这对所有测试都是通用的。
希望这对您有所帮助,
我需要将所有跳过的测试用例添加到我的 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();
}
}
这对所有测试都是通用的。
希望这对您有所帮助,