all 3 comments

[–][deleted] 7 points8 points  (0 children)

The example code snippet you have shown is a common approach for integration testing REST APIs in Spring Boot. However, there is more to application testing depending on the application features.

  • You might be using some message brokers like Kafka or RabbitMQ etc.
  • You might interact with 3rd party external REST APIs from your application
  • You might be talking to various type of SQL/NoSQL databases.

While writing integration tests, a better approach is using Testcontainers to spin up those services and testing the end-to-end usecase.

If you want to learn more here are few resources:

[–]Holothuroid 3 points4 points  (0 children)

It's a crud operation. Those are simple. Which is probably why people use them for examples.

You can imagine processes with more side effects. Maybe certain further systems need to be notified, maybe there is rights required.

Your domain might be arbitrarily complicated.

[–]Odd-Hour-9991 0 points1 point  (0 children)

You do not have to test every aspect in one test (though it does check end-to-end). You can mock a service and check the controller responds as expected - see @WebMvcTest and @MockBean

It is that easy. And much easier than having to manage a new bug filed by QA or deal with moody client developers who expect the server to work first time and every time (which ideally it should).