Skip to content

ensure order of tests whenever using a dataProvider #3109

Answered by krmahadevan
bitcoder asked this question in Q&A
Discussion options

You must be logged in to vote

@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 the ITestResult objects based on the start time

But this is being persisted into results which is declared as a HashMap instead of it being a LinkedHashMap. So the ordering is being lost. See here

I think this code block could have been just replaced with something like this (which would ensure that the ordering is going to be maintained)

Map<String, List<ITestResult>> results = testResults.stream()
        .collect(
                Collectors.groupingBy(
                        itr -> itr.getMethod().getQualifiedName

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@itkhanz
Comment options

@krmahadevan
Comment options

@itkhanz
Comment options

@krmahadevan
Comment options

Answer selected by krmahadevan
@krmahadevan
Comment options

@bitcoder
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants