Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlTest index is not set for test suites invoked with YAML #2857

Closed
1 of 7 tasks
sbaranov-parasoft opened this issue Dec 17, 2022 · 2 comments · Fixed by #2859
Closed
1 of 7 tasks

XmlTest index is not set for test suites invoked with YAML #2857

sbaranov-parasoft opened this issue Dec 17, 2022 · 2 comments · Fixed by #2859
Labels
Milestone

Comments

@sbaranov-parasoft
Copy link

sbaranov-parasoft commented Dec 17, 2022

TestNG Version

7.7

Expected behavior

ITestResult.getTestClass().getXmlTest().getIndex() should return valid test indexes when a TestNG class is invoked from YAML test suite.

Actual behavior

ITestResult.getTestClass().getXmlTest().getIndex() always returns 0.
When the same test class is invoked from an XML suite, the XmlTest.getIndex() returns expected values.

Is the issue reproducible on runner?

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

Test case sample

To reproduce run the following class:

public class TestNGTest {
    @Parameters("input")
    @Test
    public void testSomething(String input) throws Exception {
        // doSomething
    }
    @AfterMethod
    public void afterMethod(ITestResult result) {
        XmlTest xmlTest = result.getTestClass().getXmlTest();
        System.out.println("afterMethod test=" + xmlTest.getName() + ", index=" + xmlTest.getIndex());
    }
}

with the YAML test descriptor:

name: SuiteYaml
tests:
  - name: TestYaml-1
    parameters: { input: yaml_1 }
    classes:
      - test.TestNGTest
  - name: TestYaml-2
    parameters: { input: yaml_2 }
    classes:
      - test.TestNGTest

observe console output with '0' test indexes:

afterMethod test=TestYaml-1, index=0
afterMethod test=TestYaml-2, index=0

Run the same class with an equivalent XML test descriptor:

<suite name="SuiteXml">
  <test name="TestXml-1">
    <parameter name="input" value="xml_1"/>
    <classes>
      <class name="test.TestNGTest"/>
    </classes>
  </test>
  <test name="TestXml-2">
    <parameter name="input" value="xml_2"/>
    <classes>
      <class name="test.TestNGTest"/>
    </classes>
  </test>
</suite>

observe console output with correct test indexes:

afterMethod test=TestXml-1, index=0
afterMethod test=TestXml-2, index=1

Presumably the following code section in the parse method of org.testng.internal.Yaml should be setting the XmlTest indexes:

// Adjust XmlTest parents and indices
for (XmlTest t : result.getTests()) {
    t.setSuite(result);
    int index = 0;
    for (XmlClass c : t.getClasses()) {
        c.setIndex(index++);
    }
}
@juherr
Copy link
Member

juherr commented Dec 18, 2022

Hi,

Thanks for the report.

The fix should be easy. Would you like to try?

@sbaranov-parasoft
Copy link
Author

Yes, sure, I expect I'll create a pull request in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants