NSimpleTester simplifies testing the stuff you don't want to spend time creating unit tests for. For now, it's just testing properties, including raising INotifyPropertyChanged events and updating backing fields properly. Given that many of us use c# automatic properties, which are virtually impossible to mess up, the biggest benefit for many will be just to get the unit test coverage numbers up with minimal effort.
Using NSimpleTester is, well, uh, simple:
[Fact]
public void Properties_configured_correctly()
{
new PropertyTester(new AwesomeClass()).TestProperties();
}
The simple unit test above verifies that all of your properties:
- can be set and retrieved, as indicated on the property
- raise PropertyChangedEvent for classes that implement INotifyPropertyChanged
If any issues are found, an InvalidOperationException is raised and will fail your unit test. If you come across a situation where a property is causing an error, you can exclude the property from testing like so:
public void Properties_configured_correctly()
{
var propertyTester = new PropertyTester(new AwesomeClass());
propertyTester.IgnoredProperties.Add("PropertyOfTypeWithNoDefaultConstructor");
propertyTester.TestProperties();
}
There are currently 3 types of properties that can't be tested:
- Property type doesn't have a default constructor.
- Property type is a generic type definition
- The
PropertyTester
is unable to create 2 different values for the type that implements INotifyPropertyChanged. (I can't think of a situation that would cause this, but it's technically possible)