Code Coverage and auto-implemented properties RRS feed

  • Question

  • Hi,

    I have a DTO class which consists purely of auto-implemented properties like this:

    public class Person
        public string Id { get; set; }
        public string Surname { get; set; }
        public string Forename { get; set; }
        public DateTime? DateOfBirth { get; set; }

    When I run my unit tests I don't get any coverage information on this class.  I haven't written any unit tests for the class yet and expected to see low code coverage, but this class just isn't included in the coverage.

    If I add a new method to the class I do get results saying the new method isn't covered.

    Are auto-implemented properties omitted intentionally as they are part of the framework so strictly speaking you shouldn't need to write tests for them?



    Wednesday, November 10, 2010 11:36 AM


  • Hi Paul,

    Yes, automatic properties are excluded from code coverage as all they do is provide is syntactic sugar. They will never show up in code coverage.

    Kind regards,
    Tom de Koning

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Tom de Koning Wednesday, November 10, 2010 8:46 PM
    • Marked as answer by robinsonpr Thursday, November 11, 2010 9:51 AM
    Wednesday, November 10, 2010 8:46 PM