testng icon indicating copy to clipboard operation
testng copied to clipboard

JUnitTestClass sets XmlTest as null when running JUnit 4 Tests using TestNG

Open kamal-kaur04 opened this issue 2 years ago • 0 comments

TestNG Version

Note: only the latest version is supported

Expected behavior

The expectation is to get test using getXmlTest() method in Listeners such as IInvokedMethodListener and ITestListener while running JUnit 4 tests using testNG.

Actual behavior

While looking at JUnitTestClass, it seems like the xmlTest has been returned as null. Is there a way to get xmlTest in the ITestContext and ITestResult?

public class InvokedMethodListener implements IInvokedMethodListener {
    @Override
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        Thread.currentThread().setName(method.getTestMethod().getMethodName() + "@" + testResult.getTestClass().getXmlTest().getAllParameters());     // null
    }
public class TmpSuiteListener implements ITestListener {
    @Override
    public void onTestStart(ITestResult result) {
        try {
            System.out.println(result.getTestClass().getXmlTest())    // null
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Is the issue reproducible on runner?

  • [ ] Shell
  • [ ] Maven
  • [ ] Gradle
  • [ ] Ant
  • [ ] Eclipse
  • [ ] IntelliJ
  • [ ] NetBeans

Test case sample

Please, share the test case (as small as possible) which shows the issue

Contribution guidelines

Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.

kamal-kaur04 avatar Aug 15 '22 19:08 kamal-kaur04