-
Notifications
You must be signed in to change notification settings - Fork 1k
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
TestNG 6.11 to 7.5.1, execution sort order is modified #3153
Comments
Hi, @snagarjunas. Please help share a Minimal, Reproducible Example that can be used to recreate the issue. In addition to sharing a sample, please also add the following details:
It would be better if you could share a sample project that can be directly used to reproduce the problem. |
Thank you for your reply.
Yeah, I understand that we need reproducible example to solve the problem.
But there are many many tests in the package, many data provider tests,
many test annotations. At this point even I do not have minimal
reproducible code. But will try to get to it.
Till then are there any newly added parameters to run the tests in packages
in-order?
Thanks.
|
@snagarjunas - I dont think anything new was added around test execution. You can try to experimenting with an implementation of Here's a sample that shows Sample test caseimport org.testng.*;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Listeners(SampleTestCase.Statistics.class)
public class SampleTestCase {
private static final Random RANDOM = new Random();
@Test
public void z() {
sleepQuietly();
}
@Test
public void y() {
sleepQuietly();
}
@Test
public void x() {
sleepQuietly();
}
@Test(dependsOnMethods = "a")
public void b() {
sleepQuietly();
}
@Test
public void a() {
sleepQuietly();
}
private static void sleepQuietly() {
//Forcing a random sleep so that we dont have methods which have the same start time and it gives us a
//more realistic scenario.
int time = RANDOM.nextInt(1000);
if (time == 0) {
time = 100;
}
try {
TimeUnit.MILLISECONDS.sleep(time);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public static class Statistics implements ITestListener, IMethodInterceptor {
@Override
public void onFinish(ITestContext context) {
//Lets print all the passed test methods sorted based on their start time
//That will show us the order in which the methods were executed
context.getPassedTests().getAllResults()
.stream().sorted(Comparator.comparing(ITestResult::getStartMillis))
.forEach(it -> System.err.println(pretty(it)));
}
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
//Let's sort the methods based on their name
return methods.stream()
.sorted(Comparator.comparing(o -> o.getMethod().getMethodName()))
.collect(Collectors.toList());
}
private static String pretty(ITestResult itr) {
return itr.getMethod().getMethodName() + "() started at :" + itr.getStartMillis();
}
}
} Execution outputa() started at :1722398209672
b() started at :1722398210672
x() started at :1722398210978
y() started at :1722398211940
z() started at :1722398212209
===============================================
Default Suite
Total tests run: 5, Passes: 5, Failures: 0, Skips: 0
=============================================== |
@krmahadevan - In the above example can I add Priority to test y( ) to execute it firstly like below output - y( ) |
@snagarjunas - Please give it a try and then check what happens |
@krmahadevan - To expand before scenario, I have two Classes in a Package. And wanted one test to execute it at first and one test to execute at last. Sample below - TestNG: 7.5.1 Class - ResultTest1
Class - ResultTest2
Output: This is the output I get. But I am looking for ResultTest2 > test2() to be executed first (priority is -1) considering both the classes in the package and ResultTest1 > test2() to be executed at the end of all the tests (priority is 100) in the package. Expected Output: Is there a possibility to achieve this without moving priority -1 test to base class or priority 100 to after suite using any configuration parameter to consider all tests before running in package? Thank you. |
Couple of things. You should upgrade to TestNG 7.10.2 |
TestNG Version
Expected behavior
We were on TestNG 6.11 + Surefire 2.20 and maven 3.0.5. All tests in the package executed in alphabetical order
Actual behavior
We have now upgraded to TestNG 7.5.1 + Surefire 3.2.5 and maven 3.9.8 versions. Without any other changes in the pom file when we run the same command used previously, the execution order is changing.
We have tried setting runOrder (alphabetical / filesystem), but still execution order is not as before.
Is there any new setting introduced to execute in alphabetical order correctly as before?
Is the issue reproducible on runner?
Test case sample
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.
The text was updated successfully, but these errors were encountered: