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
junit in which we can sort our test cases on the based of their names in lexicographical order.
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.

Related Tags

About Author

Author Image
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.

Request for Proposal

Name is required

Comment is required

Sending message..