Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there value in unit testing auto implemented properties

It seems exceptionally heavy handed but going by the rule anything publicly available should be tested should auto-implemented properties be tested?

Customer Class

public class Customer
{
    public string EmailAddr { get; set; }
}

Tested by

[TestClass]
public class CustomerTests : TestClassBase
{
    [TestMethod]
    public void CanSetCustomerEmailAddress()
    {
        //Arrange
        Customer customer = new Customer();

        //Act
        customer.EmailAddr = "[email protected]";

        //Assert
        Assert.AreEqual("[email protected]", customer.EmailAddr);
    }
}
like image 799
ahsteele Avatar asked Jun 17 '10 21:06

ahsteele


1 Answers

I generally consider any code that is not performing an action to be not worth testing. This typically means that I don't test properties (auto-implemented or not) because they are just setting or returning a value.

This will change if the getter or setter of a property performs some sort of "work", like possibly returning one of two (or more) values based on the state of some other field/property/whatever.

If you have not seen it, I highly recommend Roy Osherove's book on Unit Testing. It addresses all sorts of "what to test and when" type questions, including this one.

like image 120
ckramer Avatar answered Oct 09 '22 16:10

ckramer