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);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With