简体   繁体   中英

Is it advisable to have sequential integration tests?

I'm new to integration tests, and currently doing it with SpringBootTest.

Roughly what I'm gathering from examples is that each method would be one integration test (corresponds to one REST call).

But what if I want to test a scenario where it's a sequence of steps? Like Create User->Update User->Delete User.

Maybe that's not called an integration test? And if so, how do I chain these inside SpringBootTest?

Well, it is okay to have a testing order at that level of testing, what I mean with level is this:

Unit Testing -> Component Testing -> Integration Testing -> end to end testing.

As you move to the right, the tests are more complex to set up and execute.

In my opinion, the tests you describe are Integration Test, so, having order is fine, but, you should try to avoid adding complexity, for instance, using a mock in-memory database like H2, and populate it when you are testing, helps a lot.

As the database is in memory, you won't need to take care of cleaning or restoring the state of that database, the data just will be gone after the testing finishes.

Now, you need to take care of the order of the test methods. JUnit5 uses a new annotation @TestMethodOrder and JUnit4 uses @FixMethodOrder that is not pretty customizable, you can find more information here

And finally, I suggest using something more BDD related like Cucumber for that kind of tests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM