Testng 跳过的测试不会显示在ExtentReports上

Testng 跳过的测试不会显示在ExtentReports上,testng,extentreports,selenium-extent-report,Testng,Extentreports,Selenium Extent Report,跳过的测试不会显示在扩展数据块报告上 我正在使用dependsonmethods,并且根据方法扩展报告应该显示带有日志跳过的测试用例。 但它会在以前的测试用例上打印跳过日志 @Test(priority = 12) void UndoRedo() { undoRedoCase.UndoRedoTest(); } @Test(priority = 13) void LockUnlock() { lockUnlockElement.LockUnlockCase(); } @

跳过的测试不会显示在扩展数据块报告上

我正在使用dependsonmethods,并且根据方法扩展报告应该显示带有日志跳过的测试用例。 但它会在以前的测试用例上打印跳过日志

   @Test(priority = 12)
void UndoRedo() {
    undoRedoCase.UndoRedoTest();
}

@Test(priority = 13)
void LockUnlock() {
    lockUnlockElement.LockUnlockCase();
}

@Test(priority = 14)
void FrameLayer() {
    layerFrame.FrameLayerCase();
}

@Test(priority = 15)
void AddImage() {
    addimage.AddImageCase();
}

@Test(priority = 16,dependsOnMethods = {"AddImage"})
void EraseImage() {
    imageErase.ImageEraseCase();
}
请检查测试执行的图像

控制台图像 5个测试用例,失败1个,跳过1个

范围报告结果。

在以前的测试用例日志上打印的跳过的测试用例日志


跳过的测试用例未打印在扩展数据块报告中。

我有一个类似的问题,但处理问题的方式不同。当我明确地告诉它test.pass或test.fail时,有一个after方法非常有效,但我很难让extent reporter捕获并记录跳过的测试。TestNG报告正在跳过完整的测试,希望在扩展输出中看到这一点

    @AfterMethod
public void getResult(ITestResult result) {
    if(result.getStatus() == ITestResult.FAILURE) {
        test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" FAILED ", ExtentColor.RED));
        test.fail(result.getThrowable());
    }
    else if(result.getStatus() == ITestResult.SUCCESS) {
        test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" PASSED ", ExtentColor.GREEN));
    }
    else if(result.getStatus() == ITestResult.SKIP) {
        test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" SKIPPED ", ExtentColor.RED));
    }
    else {
        test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" SKIPPED ", ExtentColor.ORANGE));
        test.skip(result.getThrowable());
    }
}
单一验证的一个示例:

try {
    softAssert.assertEquals(plain1, plain2);
    test.pass("PASS: Field is edited");
} catch (AssertionError e) {
    test.fail("FAIL: Field is NOT edited");
    test.fail(e);
    throw (e);
}

我也遇到过这个问题,下面的代码对我很有用。 像这样定义testListener,然后在基类启动之前使用@listenersTestListeners.class在基类中调用这个testListener类

注意:我使用了Spark Extentreport

public class TestListeners implements ITestListener {

@override public void onTestSkipped(ITestResult result) {

Baseclass.extenttest = Baseclass.extent.createTest(result.getMethod().getDescription()).assignCategory("SkipedTest");
Baseclass.extenttest .log(Status.SKIP, result.getThrowable());
Baseclass.extenttest .log(Status.SKIP, result.getMethod().getDescription());
Baseclass.extenttest .log(Status.SKIP,  MarkupHelper.createLabel(result.getName(), ExtentColor.YELLOW));
Baseclass.extent.flush();
} }
在测试类中定义@test,如下所示

@Test(description = "Test Case name", dependsOnMethods = { "Name of method on which it depends" })

谢谢分享,但我已经尝试过该代码,在我的案例中不起作用。