Reputation: 169
I have a controller class and a service class. Controller has endpoints and service layer has functions performing something specific (inserting, loading a file and counting lines, updating, etc).
Now what I want to know is, should I unit test an endpoint(controllers) as a whole or individual functions present in the service layer? I've really been confused. Please help.
Upvotes: 2
Views: 73
Reputation: 3766
You need two test classes
Controller class test - This class will test the your endpoints and their functionality. You can achieve this using RequestBuilder and MockMvc. You can mock your service class call.
Service class test - This class will test your actual business logic (inserting, loading a file and counting lines, updating, etc.). You can mock your repository call and any other calls if there.
Upvotes: 0
Reputation: 12953
Yes, you should have two test classes-
One for the controller, with the service mocked, testing the controller's functionality.
One for the service, with the dal layer mocked, teating the service
Upvotes: 6