-1

Currently I have an entity called Product with the respective ProductRepository and ProductService.

For ProductService, I have tests for:

  • Read (Covering Create too)
  • Update
  • Delete

Besides achieving higher test coverage, is there any particular reason to also test ProductRepository?

What I think:

It could be possible that, one day, ProductService gets added complexity that needs to be tested within the previous mentioned tests, giving the ProductRepository a perspective of 'testing the most primitive part of the layer' (The CRUD against the database), therefore justifying its testing.

2
  • Does the service do something else besides the functions you have mentioned? Seems like it's simply duplicating the logic of the repository, in which case it seems to be pretty useless. Commented Apr 14, 2018 at 15:45
  • Right now? Yes. Basic CRUD with no added transformations or complexity. Commented Apr 14, 2018 at 16:13

1 Answer 1

2

As hinted at it the comments, your ProductService at the moment seems to be an abstraction for the sake of having an abstraction. If you truly don't have any Product-related business logic, then test ProductRepository and just drop ProductService.

However, in my experience it's more likely you do have some Product-related business logic somewhere and that should be moved into ProductService, meaning you want to test them both.

1
  • While ProductService still doesn't have any business logic yet, we don't know how (or when) It is going to change. Your answer makes sense. Thank you. Commented Apr 15, 2018 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.