Anton
Anton

Reputation: 940

TestNG 6.11 Invoker

Recently upgraded from TestNG 6.9.10 to 6.11. Upon doing so I noticed that our TestNG Invoker class had a deprecated method: "addListener".

    String filePath = System.getProperty("user.dir") + "\\testng.xml";

    TestListenerAdapter tla = new TestListenerAdapter();
    TestNG testng = new TestNG();

    File file = new File(filePath);
    if (file.exists() && !file.isDirectory()) {
        System.out.println("testng.xml file found at " + filePath);
        List<String> suites = Lists.newArrayList();
        suites.add(filePath);
        testng.setTestSuites(suites);
        testng.addListener(tla);  <-- Deprecated
        testng.run();
    } else {
        System.exit(0);
    }

I can't find any documentation on how this is supposed to work now. TestNG hasn't updated the documentation on their website. Has anyone been able to figure out the new method or procedure?

The build shows this:

 [INFO] /C:/Users/jsmith/workspace/myproj/src/main/java/mypackage/TestngInvoker.java: C:\Users\jsmith\workspace\myproj\src\main\java\mypackage\TestngInvoker.java uses or overrides a deprecated API.
 [INFO] /C:/Users/jsmith/workspace/myproj/src/main/java/mypackage/TestngInvoker.java: Recompile with -Xlint:deprecation for details.

Upvotes: 4

Views: 940

Answers (1)

juherr
juherr

Reputation: 5740

All addListener are deprecated except addListener(ITestNGListener) which the one you are supposed to use.

Due to the Java resolution, the selected method is a deprecated one.

You have 2 options:

  1. Wait for the removal of the deprecated methods, and Java will find the expected method.
  2. Force the resolution by a cast:

    testng.addListener((ITestNGListener) tla);
    

Upvotes: 3

Related Questions