4

When we use an inner class, fields will not be covered unless otherwise we declare them with {get;set;}(even though they are accessible from the test class) Also these lines are not get counted as to be covered lines. Is this the normal standard behavior?

e.g. In below sample class I'm using an inner class. There you can see that strFirstName has not been covered, though it has been called from the main class constructor. The field count has been called and covered which is declared with {get;set;}

code coverage issue

  • Why @TestVisible public? – Adrian Larson Sep 28 '16 at 12:59
  • Yes, no point sorry. This is just one of the sample classes I tried in different ways. – highfive Sep 28 '16 at 13:05
6

The line containing strFirstName does not require coverage because you only declare the variable, but do not instantiate it. Notice how strTitle requires coverage, but there you perform assignment. This behavior has nothing to do with whether or not the class definition is top-level.

The other lines that are not covered in your screenshot are the class declarations themselves. Class declarations never require coverage. Notice how neither your inner class declaration nor your top level class declaration require coverage.


None of the lines in white count against you. Your posted coverage is 8/8. Note from Checking Code Coverage:

Lines of code that are covered by tests are blue. Lines of code that aren’t covered are red. Lines of code that don’t require coverage (for example, curly brackets, comments, and System.debug calls) are left white.

  • Oh yes I tried instantiating inner class field without {get;set;} and it's now caught. If we don't instantiate them is it ok to go without having code coverage on them? Confusion is these lines are counted against apex usage, so if we have considerable amount of such lines(without instantiating) will it be a blocker for the 75% coverage at deployment? – highfive Sep 28 '16 at 13:13
  • 2
    If the line is white, it does not count towards the number of lines you must cover. – Adrian Larson Sep 28 '16 at 13:14
  • This is much helpful. Debug statements, class declarations are fine but never thought that a field doesn't need the coverage. Thanks for the info and reference @AdrianLarson – highfive Sep 28 '16 at 13:21
  • @highfive If you think about it, there isn't any code to execute there, per se. You don't do anything at all, really. – Adrian Larson Sep 28 '16 at 13:23
  • That's what I was also thinking lol :D – highfive Sep 28 '16 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.