Welcome to the Class Tester

This project started life as a blog post and some source code (read the
original post) but due to public demand (at least 2 comments!) it has now gone open source. The project has undergone a fairly significant refactoring since then with a number of new features and improvements:

Stuff that nobody ever tests directly because it would be so time consuming. I found this very annoying because of the loss of code coverage in my test suite and then disaster struck. I made a change to such code that accidentally broke one of the properties
(two different public getters returned the same private string).

Something had to be done and the Automatic Class Tester project was born!

An exception is thrown when a problem is found which should cause your tests to fail.

How it works

The PropertyTester simply uses reflection to discover the subject's properties. Random values are then injected via the property setters and the getter is invoked and the ClassTester verifies that we get the same value back. Here we test our Person class
above:

Some properties just can't be tested in this way, either because they perform some funky logic that is dependant on other state in the class or because they don't return the same value that was set. Like this nonsensical example below that we'll
add to our person class:

Testing Constructors

The QualityTools library can also help you test your constructors thanks to the ConstructorTester. It's a very common practice to create a custom constructor to help inject property values at construction time. Like this:

This static method will test all constructors available on the object by creating random values for each parameter (as best it can). Again, if there are some constructors that you need to skip over because they have some funky logic you can add them to a blacklist.
Maybe you have to blacklist a particular constructor because it takes a parameter that the ConstructorTester can't create, like an Interface.

[Test]
public void TestPersonConstructors()
{
ConstructorTester tester = new ConstructorTester(typeof(Person));
// we specify the signature of the constructor to be ignored
tester.IgnoredConstructors.Add(typeof(string), typeof(ISomeInterface), typeof(object));
tester.TestConstructors(true);
}

In this example we're going to test all the types within the ExampleAssembly (obviously, it uses the PropertyTester and ConstructorTester under the covers). We also specifically exclude the ExampleAssembly.SomeNamespace so any types belonging to that namespace
won't be tested.

Remember kids! This is just a helper and isn't intended to remove the need to write unit tests. It's only there to cover the basic stuff that people don't normally test. If you exclude a namespace, type, property or constructor then you should
consider adding a manual test.