Reputation: 37746
I have a java class containing 3 methods:
public class Test{
public void orange(){
}
public void apple(){
}
public void mango(){
}
}
I want to execute 3 methods mentioned above sequentially/orderly as i have written by Selenium RC and TestNG. How can I do this?
Upvotes: 0
Views: 4115
Reputation: 2889
In addition to using sequential=true
on the class, you can also set a priority on the methods themselves.
@Test(priority=1)
public void orange(){}
@Test(priority=2)
public void apple(){}
@Test(priority=3)
public void mango(){}
Upvotes: 0
Reputation: 3496
I suggest using dependsOnGroups. Hence you club your test method as one group and provide dependency over this group. So tomorrow if you refactor your method name, your dependency structure would not be broken. For more on dependsOnGroups look here
Upvotes: 0
Reputation: 1693
The easy way is to just change @Test
to @Test(singleThreaded=true)
. If you do, all of the tests in your class will run sequentially in a single thread.
Or
If you want to be explicit about the order that the tests should run in, you can use the annotation @dependsOnMethods
public void orange(){}
@Test(dependsOnMethods = { "orange" })
public void apple(){}
@Test(dependsOnMethods = { "apple" })
public void mango(){}
This is also nice if you want some, but not all, of the methods in a class to run sequentially.
http://testng.org/doc/documentation-main.html#dependent-methods
Upvotes: 5
Reputation: 5645
Just change the @Test
to @Test(singleThreaded=true)
and you're good to go.
http://testng.org/javadoc/org/testng/annotations/Test.html#singleThreaded%28%29
Upvotes: 3
Reputation: 536
In your test class you try this annotation at class level itself.
@Test(sequential = true)
Upvotes: 0