Ronaldo Lanhellas
Ronaldo Lanhellas

Reputation: 3336

Should test @RestController or just @Service

I have a application with 3 layers: Controller, Service and Repository.

Well, as I said, I just make test classes for Service, because here is my business logic. My question is about how to create test for controller classes, is it really necessary ? Is this a good practice ?

Upvotes: 0

Views: 519

Answers (1)

codependent
codependent

Reputation: 24452

Of course it’s a must. We have to test all layers of the applications, as each or them provides particular elements: service-business logic, repository-data access, controller-http input and output.

For each endpoint, you can test if it returns the appropriate status code, headers, body, etc. Furthermore, you should test error responses, as well. Think of all the possibilities per endpoint, 200, 201, 4xx, 5xx cases.

Upvotes: 3

Related Questions