-
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
Class Level Test Annotation does not allow the setting of priorrities for the methods #2734
Comments
I would like to add that it seems that the order of execution is a bit odd, maybe that explains the priority thing:
It seems that in this case the Test listener starts before the annotationtransfomer. Normally it is the other way around. |
@baubakg - Please recheck this. I can't reproduce this import org.testng.annotations.Test;
public class TestsPriority2 {
public static int value = 100;
@Test
public void testAAA() {
value -= 20;
}
@Test
public void testBBB() {
value *= 2;
}
} import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;
public class PriorityThing implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,
Method testMethod) {
if (testMethod != null && testMethod.getName().equals("testAAA")) {
annotation.setPriority(2);
System.err.printf("transform : Changing priority. priority for %s is %s%n",
testMethod.getName(), annotation.getPriority());
}
}
} import org.assertj.core.api.Assertions;
import org.testng.TestNG;
import org.testng.annotations.Test;
public class IssueTest {
@Test
public void runTest() {
TestNG testng = new TestNG();
testng.addListener(new PriorityThing());
testng.setTestClasses(new Class[]{TestsPriority2.class});
testng.setVerbose(2);
testng.run();
Assertions.assertThat(TestsPriority2.value).isEqualTo(180);
}
} Output
|
Sorry @krmahadevan I mixed my examples. Hre is the test sample which fails th piority stting (I have also updated the original description): @Test
public class TestsPriority2 {
public static int value = 100;
public void testAAA() {
value-=20;
}
public void testBBB() {
value*=2;
}
} |
It is a design issue: when you set the annotation on the class, there is no annotation on methods. |
Thanks for the feedback @juherr . Ok. Do you by any chance have a work around for setting the priority or changing the order of execution of the methods in this example? |
* #2734 keep the initial order of listeners We need to run listeners at the same order in which they were declared in @listeners({First.class, Second.class, Third.class})
TestNG Version
7.5
Expected behavior
We should be able to set the priority of a test method even if the Test annotation is on the class.
Actual behavior
The piorities we set are ignored
Is the issue reproducible on runner?
Test case sample
In my example I have a test case that ha different results based on the order. I will ry and change the order so that testBBB is executed first. I use the listener to make sure that the priority for the other method is higher.
Test Sample
(Edited from the original ass I had used a wrong example):
Test
Listener
The text was updated successfully, but these errors were encountered: