简体   繁体   English

RunListener 接口的 testSuccess 方法实现

[英]testSuccess method implementation for RunListener interface

I have a class that extends RunListener interface (JUnit framework) so i will be able to perform different action depending on the test result.我有一个扩展 RunListener 接口(JUnit 框架)的类,因此我将能够根据测试结果执行不同的操作。 My issue is that the interface has no testSuccess method.我的问题是接口没有 testSuccess 方法。 (for example the ITestListener from TEstNG framework has a onTestSuccess method) Should i create my own testSuccess method in the class extending RunListener or what can i do? (例如,来自 TestNG 框架的 ITestListener 有一个 onTestSuccess 方法)我应该在扩展 RunListener 的类中创建我自己的 testSuccess 方法还是我能做什么?

thank you谢谢你

RunListener class http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html Example of implementation https://memorynotfound.com/add-junit-listener-example/ RunListener 类http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html实现示例https://memorynotfound.com/add-junit-listener-example/

i expected that the RunListener interface will have a testSuccess method but it doesn't.我预计 RunListener 接口会有一个 testSuccess 方法,但它没有。

private static final Description FAILED = Description.createTestDescription("failed", "failed");

public void testFinished(Description description) throws Exception {
        System.out.println("Finished test: " + description.getMethodName());
        if (description.getChildren().contains(FAILED)) {
            // action for test failed
        } else {
            // action for test success 
        }
    }

    public void testFailure(Failure failure) throws Exception {
        System.out.println("Failed test: " + failure.getDescription().getMethodName());

// mark the test as being failed 
        failure.getDescription().addChild(FAILED);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM