Search code examples
c#unit-testingtddarrange-act-assert

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);
    }
}

Solution

  • What happens if you switch from auto-implemented properties to something entirely different? The test only seems redundant because you know the implementation - which you should not consider when writing tests.

    Of course, this depends on the likelihood of your actually changing the implementation any time soon.