Line of code in Unit Test that is not accepted by code coverage

1

I have a test routine where a particular line of code is not supported by the coverage.

ThisisatesttoreturntheDefaultValuesincetheobjectthatcallsitisnull.

Thisisthemethodyouaretesting

public static TResult IfNotNull<TObject, TResult>(this TObject obj, Func<TObject, TResult> action, TResult defaultValue) { if (action == null) throw new ArgumentNullException(nameof(action)); return obj == null ? defaultValue : action(obj); }

See that it is scoring as 100% tested.

How do I solve this problem?

    
asked by anonymous 25.01.2017 / 12:18

1 answer

0

I do not know what benefit you're looking for, to be covered in tests in general (% with%). Certainly your IDE should be including the tests on the cover. The cover should be used as a tool where you can view areas of code that are covered or not covered by tests. Keep in mind that even if the coverage shows that the lines in the code are covered, that does not mean that the desired behavior of the function is being tested. Looking at this function / method I see 3 behaviors / functionalities that should be tested if these are the requirements.

  • when ShouldReturnDefaultValueSinceObjectIsNull is action then null
  • when throw new ArgumentNullException(nameof(action)); is obj then null
  • when return 'defaultValue'; is not obj then null
  • 01.02.2017 / 14:19