TestNG 6.11 Invoker

Recently updated from TestNG 6.9.10 to 6.11. After that, I noticed that our TestNG Invoker class has an obsolete 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 cannot find documentation on how this should work now. TestNG has not updated the documentation on its website. Could anyone define a new method or procedure?

The assembly shows the following:

 [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.
+4
source share
1 answer

Everything is addListenerout of date, except addListener(ITestNGListener)which you should use.

Due to Java permission, the selected method is deprecated.

You have 2 options:

  • Wait for the deprecated methods to be removed, and Java will find the expected method.
  • Force casting:

    testng.addListener((ITestNGListener) tla);
    
+2
source

Source: https://habr.com/ru/post/1675616/


All Articles