Reputation: 31
I am using latest version of TestNG but still not able execute testcases by the order it has been written(avoiding priority annotation tag).
import org.testng.annotations.Test;
public class NewTest {
@Test
public void b() {
System.out.println("inside b method");
}
@Test
public void a() {
System.out.println("inside a method");
}
}
I have also used IMethodInterceptor but still no go.
in testng.xml also added listeners:
<listeners>
<listener class-name="testngdemo.PriorityInterceptor" />
</listeners>
but still getting following output
inside a method
inside b method
Priority interface:
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({METHOD, TYPE})
public @interface Priority { int value() default 0; }
Upvotes: 0
Views: 1842
Reputation: 2799
If you run your test cases from testng xml then include your test methods in the order you want like this:
<classes>
....
....
<class name="Fully qualified class name without extension">
<methods>
<include name="method_1" />
<include name="method_1" />
.....
.....
<include name="method_N" />
</methods>
</class>
<class name="test.Test2" />
....
....
</classes>
Upvotes: 1
Reputation: 5740
What you are trying is not really clear but if you have a dependency between a
and b
, just use the dependsOnMethods
feature:
public class NewTest {
@Test
public void b() {
System.out.println("inside b method");
}
@Test(dependsOnMethods = { "b" })
public void a() {
System.out.println("inside a method");
}
}
Upvotes: 0