简体   繁体   English

IConfigurationListener参数getInstance()方法返回null

[英]IConfigurationListener parameter getInstance() method returns null

I have a problem with IConfigurationListener from org.testng package . 来自org.testng package IConfigurationListener有问题。 I would like to use it to perform some actions after method annotated with @AfterTest . 在使用@AfterTest注释的方法之后,我想用它来执行一些操作。

Test class: 测试类:

import org.testng.annotations.AfterTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners(Listener.class)
public class Tests {

    @Test
    public void test1() {
        System.out.println("test 1");
    }

    @AfterTest
    public void after(){
        System.out.println("After test");
    }
}

Listener class: 听众课程:

import org.testng.IConfigurationListener;
import org.testng.ITestResult;

public class Listener implements IConfigurationListener {

    public void onConfigurationSuccess(ITestResult itr) {
        System.out.println("Conf result: " + itr.getInstance()); // LINE
        System.out.println("Conf status: " + itr.getStatus());
    }

    public void onConfigurationFailure(ITestResult itr) {
    }

    public void onConfigurationSkip(ITestResult itr) {
    }
}

So the problem is that line (with comment LINE ) returns Conf result: null . 所以问题是line(带注释LINE )返回Conf result: null But next line return status of executed method so I'm confused. 但是下一行返回执行方法的状态让我感到困惑。 When I use ITestListener for the test method and perform getInstance() method on the result, then I receive an object which is not null . 当我使用ITestListener作为测试方法并对结果执行getInstance()方法时,我收到一个非null的对象。 Is there any solution to use IConfigurationListener and get a result that is not null ? 是否有任何解决方案使用IConfigurationListener并获得非null的结果?

问题由https://github.com/cbeust/testng/pull/1320解决,将在下一个TestNG版本(6.10后)中提供

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

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