首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跳过的测试不会显示在ExtentReports上

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

Stack Overflow用户
提问于 2019-12-04 19:01:54
回答 2查看 887关注 0票数 0

跳过的测试不会显示在盘区报告中。

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

代码语言:javascript
复制
   @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

范围报告结果。

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

跳过的测试用例未在范围报告中打印。

EN

回答 2

Stack Overflow用户

发布于 2019-12-24 08:08:29

我有一个类似的问题,但处理这个问题的方式不同。我有一个after方法,当我显式地告诉它test.pass()或test.fail()时,它可以很好地工作,但我正在努力让扩展报告器捕获并记录跳过的测试。TestNG报告说,完整的测试正在被跳过,希望看到在输出的范围内。

代码语言:javascript
复制
    @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());
    }
}

一个单一验证的示例:

代码语言:javascript
复制
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);
}
票数 1
EN

Stack Overflow用户

发布于 2021-05-14 12:28:53

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

注意:我已经使用了Spark Extentreport

代码语言:javascript
复制
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,如下所示

代码语言:javascript
复制
@Test(description = "Test Case name", dependsOnMethods = { "Name of method on which it depends" })
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59174476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档