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

2857 xml test index in yaml suite #2859

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2857: XmlTest index is not set for test suites invoked with YAML

7.7.1
Fixed: GITHUB-2854: overloaded assertEquals methods do not work from Groovy (Krishnan Mahadevan)
Expand Down
4 changes: 4 additions & 0 deletions testng-core-api/src/main/java/org/testng/xml/XmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ public int getIndex() {
return m_index;
}

public void setIndex(int index) {
m_index = index;
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
6 changes: 4 additions & 2 deletions testng-core/src/main/java/org/testng/internal/Yaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ public static XmlSuite parse(String filePath, InputStream is, boolean loadClasse
result.setFileName(filePath);

// Adjust XmlTest parents and indices
int testIndex = 0;
for (XmlTest t : result.getTests()) {
t.setIndex(testIndex++);
t.setSuite(result);
int index = 0;
int classIndex = 0;
for (XmlClass c : t.getClasses()) {
c.setIndex(index++);
c.setIndex(classIndex++);
}
}

Expand Down
14 changes: 14 additions & 0 deletions testng-core/src/test/java/test/yaml/YamlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.testng.Assert;
Expand All @@ -18,6 +19,7 @@
import org.testng.internal.YamlParser;
import org.testng.xml.SuiteXmlParser;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import org.testng.xml.internal.Parser;
import test.SimpleBaseTest;

Expand Down Expand Up @@ -100,6 +102,18 @@ public void testLoadClassesFlag() throws IOException {
}
}

@Test(description = "GITHUB-2857")
public void testXmlTestIndex() throws IOException {
YamlParser yamlParser = new YamlParser();
String yamlSuiteFile = "src/test/resources/yaml/testXmlTestIndex.yaml";
XmlSuite suite = yamlParser.parse(yamlSuiteFile, new FileInputStream(yamlSuiteFile), false);
List<XmlTest> tests = suite.getTests();
assertThat(tests.size()).isEqualTo(3);
for (int i = 0; i < tests.size(); i++) {
assertThat(tests.get(i).getIndex()).isEqualTo(i);
}
}

private Throwable getRootCause(Throwable throwable) {
return throwable.getCause() != null ? getRootCause(throwable.getCause()) : throwable;
}
Expand Down
14 changes: 14 additions & 0 deletions testng-core/src/test/resources/yaml/testXmlTestIndex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: SuiteYaml
tests:
- name: TestYaml-1
parameters: { input: yaml_1 }
classes:
- test.TestNGTest
- name: TestYaml-2
parameters: { input: yaml_2 }
classes:
- test.TestNGTest
- name: TestYaml-3
parameters: { input: yaml_3 }
classes:
- test.TestNGTest