ensure order of tests whenever using a dataProvider #3109
-
Hi everyone, public class DataDrivenExamples {
@DataProvider(name = "numbers")
public static Object[][] evenNumbers() {
// the last data/example if not correct on purpose, to fail the test
return new Object[][]{{1, false}, {2, true}, {4, true}, {5, true}};
}
@Test(dataProvider = "numbers")
public void givenNumberFromDataProvider_ifEvenCheckOK_thenCorrect(Integer number, boolean expected) {
assertEquals(expected, number % 2 == 0);
}
} Note: tested using TestNG 7.9.0 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
@krmahadevan could you please have a look at this discussion and sample code-snippet and suggest if there's a way to preserve order of tests in this scenario? |
Beta Was this translation helpful? Give feedback.
@itkhanz - The root cause of the issue is NOT how TestNG runs the tests but its related to how TestNG captures the results.
I see that the code does use a
LinkedHashSet
to sort theITestResult
objects based on the start timeBut this is being persisted into
results
which is declared as aHashMap
instead of it being aLinkedHashMap
. So the ordering is being lost. See hereI think this code block could have been just replaced with something like this (which would ensure that the ordering is going to be maintained)