What is the best way to test or ignore coverage of the following method? Notice that the update method just calls the service and I must cover 80% of the class/code.
There are two answers.
If you need the update
method to be covered by your tests, simply write a (unit) test that calls it. (It shouldn't be difficult.) This would be my recommendation.
By inspection, you could conclude that the method is trivial and doesn't need to be tested. You may be able to exclude it from the test coverage1. Alternatively, you could "solve" this by finding some other non-covered code, and writing tests to cover that code ... to boost the overall coverage to the required 80%.
But the flipside is that this method is not completely trivial. If for some reason userService
is null
, this method will raise an NPE. Maybe some test cases are needed for picking up cases where userService
hasn't been configured correctly.
And while the current implementation of update
seems trivial, someone might modify the method in the future to do something more complicated. Simply calling it may pick up (future) problems that wouldn't otherwise be noticed.
1 - It will depend on the coverage tool you use. You haven't mentioned what that is.