Junit Stop Operation Test

I have 4 rest api for crud operations. So when I write junit for those resting api,

1. Do I have to write one test case that performs the entire crud operation, or should it be different test cases for each other api?

2. If I write a separate test case, is it possible to use the record created in the case of creating a test in the update or to get test cases. In this case, there is a relationship between each test case.

3. How can I get Junit to run test cases in execution order, given that my test method is not in alphabetical order.

+4
source share
1 answer

DISCLAIMER: There is no “one correct answer”.

SUGGESTIONS:

  • If at all possible, you should encode your JUnit tests so that each one runs independently. There should be no dependency to “order” between any particular test.

  • All things being equal, I would recommend a different test for each operation.

  • I would also recommend liberal use of fixtures or a Mock object library, such as Mockito .

  • Otherwise, Junit 4.11 and higher offers @ Annotation FixMethodOrder

+3
source