How To Run Integration Test Cases Sequentially
Posted By : Vipul Pandey | 13-Dec-2017
Need for sequential test cases: When we are running integration test cases the output of first test case is required as input or send like when we are
creating data and in next we need to delete that so in this case running test cases is must in order to get the proper success, this can be achieved by FixMethodOrder annotation of
To run this we are using the Spring runner class to run this
Ex:
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class abs {
int num1 = 25;
int num2 = 10;
static int result; // to use the same updated object at each block as static is a class level variable
@Test
public void test1_AddNumbers() throws Exception {
result = num1 + num2;
System.out.println("Result after addition:" + result);
}
@Test
public void test2_substractSum() throws Exception {
System.out.println("Result in Second Block:" + result);
result = num1 - num2;
System.out.println("Result After substraction:" + result);
}
@Test
public void test3_print() throws Exception {
System.out.println(num1 + " " + num2);
}
}
Note: I have added the test_1, test_2 to make it increasing order before my test cases name so that the Fix order will chwck and execute it.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Vipul Pandey
Vipul Pandey is a good team-player & developing application on MEAN and java spring boot. Vipul loves to keep rotating fingers in his keyboard until he creates somethings inspiring.Hobbies are playing cricket ,swimming & photography.