jeudi 2 février 2017

IConfigurationListener parameter getInstance() method returns null

I have problem with IConfigurationListener from org.testng package. I would like to use it to perform some actions after method annotated with AfterTest annotation.

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) {
       // TODO Auto-generated method stub
       System.out.println("Conf result: " + itr.getInstance()); // LINE
       System.out.println("Conf status: " + itr.getStatus());

   }

   public void onConfigurationFailure(ITestResult itr) {
       // TODO Auto-generated method stub

   }

   public void onConfigurationSkip(ITestResult itr) {
       // TODO Auto-generated method stub

   }
}

So the problem is that line (with comment LINE) returns Conf result: null. But next line return status of executed method so I'm confused. When I use ITestListener for test method and perform getInstance() method on result then I recieve object which is not null. Are there any solution to use IConfigurationListener and get result that is not null?

Aucun commentaire:

Enregistrer un commentaire