<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>classtester Wiki &amp; Documentation Rss Feed</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home</link><description>classtester Wiki Rss Description</description><item><title>UPDATED WIKI: AssemblyTester</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
The AssemblyTester
&lt;/h1&gt; &lt;br /&gt;The AssemblyTester uses the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; and &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and can remove much of the coding previously required to use them by applying these tests to all the types in an assembly, subject to exclusions that you can specify.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
How it works
&lt;/h3&gt; &lt;br /&gt;To test an assembly simply create an instance of the AssemblyTester passing it the name of the Assembly to test.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools&amp;quot;);
&lt;/pre&gt; &lt;br /&gt;Now you can call the AssemblyTesters TestAssembly method which looks like this:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     public void TestAssembly(bool testProperties, bool testConstructors)
&lt;/pre&gt; &lt;br /&gt;The testProperties and testConstructors parameters should be fairly self explanatory!&lt;br /&gt; &lt;br /&gt;The example below aims to test both constructors and properties in the &amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot; assembly.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
     tester.TestAssembly(true, true);
&lt;/pre&gt; &lt;br /&gt;The AssemblyTester will throw an exception with a detailed description of errors encountered when testing an assembly. Here's an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTesterTest.AssemblyTester_PassWithExclusions : FailedTheJoyOfCode.QualityTools.AssemblyTestException: 
Testing the assembly TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: 'fe6faacc-3ea8-45a0-8c5c-dc2e0021065b')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: 'cf04ca44-73dc-4147-bb3e-2a1a0d2c52b3', out: '819e635d-4dc6-4e6c-b141-75f0212cb242')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
 
The type TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1 is an open 
Generic Definition (e.g. Class&amp;lt;T&amp;gt;. Only closed generic types Class&amp;lt;int&amp;gt; are currently supported.
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
 
Cannot create an instance of TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T] 
because Type.ContainsGenericParameters is true. 
[TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
&lt;/pre&gt; &lt;br /&gt;Not all types in an assembly qualify for automatic testing of constructors or properties. Looking at the errors produced above it is clear that the two first errors are should be fixed (A property which is not mapped correctly and a constructor which does not map correctly to the corresponding property). The last two errors indicates that the AssemblyTester can not test this particular type because it contains generic parameters.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Exclusions
&lt;/h2&gt; &lt;br /&gt;To still use the AssemblyTester on this module we can skip these last two issues. This can be done in two ways, specifying one or more types to exclude or specifying a namespace to exclude. &lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a type
&lt;/h3&gt; &lt;br /&gt;The example excludes the class which is not qualified for automatic testing to the AssemblyTester.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot;);
     tester.Exclusions.AddType(typeof(GenericClass&amp;lt;&amp;gt;));
     tester.TestAssembly(AssemblyTester.TestTarget.Properties | AssemblyTester.TestTarget.Constructors);
&lt;/pre&gt; &lt;br /&gt;When running the test again the AssemblyTester only produces the following errors.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
TheJoyOfCode.QualityTools.AssemblyTestException: Testing the assembly 
TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: '1e5101b5-e9e9-4d69-b13c-83863f70a7b6')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: '2bf2002e-b505-4413-a8f9-97036c40f720', out: '8a447a00-2f17-4d27-bb25-1fc66bf2c39d')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
&lt;/pre&gt; &lt;br /&gt;The errors above are errors which the AssemblyTester has been designed to detect; errors in mapping properties to fields and mapping values to constructors. So to make the test pass we need to fix those errors!&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a namespace
&lt;/h3&gt; &lt;br /&gt;The example below excludes all types in the namepace &amp;quot;ExampleAssembly.SomeNamespace&amp;quot; namespace &lt;b&gt;but does not exclude types in any sub namespaces.&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
&lt;/pre&gt; &lt;br /&gt;We could specify that all types within a numespace and sub-namespaces are excluded like so:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, true);
&lt;/pre&gt; &lt;br /&gt;For example, this would also exclude any type in the &amp;quot;ExampleAssembly.SomeNamespace.SomeSubNamespace&amp;quot; too.&lt;br /&gt; &lt;br /&gt;You can have as many exclusions as you like and can combine type exclusions with namespace exclusions. Easy peasy.&lt;br /&gt; &lt;br /&gt;If you need to exclude a type from an assembly test because of one &lt;i&gt;funky&lt;/i&gt; property or constructor you can always target that type directly with the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; or &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and exclude the property/type specifically. Best of both worlds.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Adding your own exclusion rules
&lt;/h2&gt;It's easy to extend the exclusion policies available in the AssemblyTester by creating your own class that inherits from TestExclusion. Imagine you want to be able to exclude any class that starts with the letter 'S'. First we need a new &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private class StartsWithSExclusion : TestExclusion
{
    public override bool IsExcluded(Type type)
    {
        return type.Name.StartsWith(&amp;quot;S&amp;quot;);
    }
}
&lt;/pre&gt; &lt;br /&gt;Now we just have to add that type to the Exclusions as follows:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.Add(new StartsWithSExclusion());
&lt;/pre&gt; &lt;br /&gt;... and any types whose name starts with an S won't be tested.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
FAQ
&lt;/h2&gt; &lt;br /&gt;&lt;b&gt;Q:&lt;/b&gt; It's nice that I can exclude whole types and namespaces using the AssemblyTester but why can't I specify a single property on a type that should be excluded.&lt;br /&gt;&lt;b&gt;A:&lt;/b&gt; This feature is deliberately not included to date. The practice in this case is to exclude the type from the assembly test like so:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTester tester = new AssemblyTester(&amp;quot;MyType, MyAssembly&amp;quot;);
tester.Exclusions.AddType(typeof(TypeWithUntestableProperty));
tester.TestAssembly(true, true);
&lt;/pre&gt; &lt;br /&gt; Now, add another test to target that class using the PropertyTester directly:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
PropertyTester tester = new PropertyTester(new TypeWithUntestableProperty));
tester.TestProperties();
&lt;/pre&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Wed, 09 Jan 2008 16:19:11 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: AssemblyTester 20080109041911P</guid></item><item><title>UPDATED WIKI: AssemblyTester</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
The AssemblyTester
&lt;/h1&gt; &lt;br /&gt;The AssemblyTester uses the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; and &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and can remove much of the coding previously required to use them by applying these tests to all the types in an assembly, subject to exclusions that you can specify.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
How it works
&lt;/h3&gt; &lt;br /&gt;To test an assembly simply create an instance of the AssemblyTester passing it the name of the Assembly to test.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools&amp;quot;);
&lt;/pre&gt; &lt;br /&gt;Now you can call the AssemblyTesters TestAssembly method which looks like this:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     public void TestAssembly(bool testProperties, bool testConstructors)
&lt;/pre&gt; &lt;br /&gt;The testProperties and testConstructors parameters should be fairly self explanatory!&lt;br /&gt; &lt;br /&gt;The example below aims to test both constructors and properties in the &amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot; assembly.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
     tester.TestAssembly(true, true);
&lt;/pre&gt; &lt;br /&gt;The AssemblyTester will throw an exception with a detailed description of errors encountered when testing an assembly. Here's an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTesterTest.AssemblyTester_PassWithExclusions : FailedTheJoyOfCode.QualityTools.AssemblyTestException: 
Testing the assembly TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: 'fe6faacc-3ea8-45a0-8c5c-dc2e0021065b')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: 'cf04ca44-73dc-4147-bb3e-2a1a0d2c52b3', out: '819e635d-4dc6-4e6c-b141-75f0212cb242')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
 
The type TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1 is an open 
Generic Definition (e.g. Class&amp;lt;T&amp;gt;. Only closed generic types Class&amp;lt;int&amp;gt; are currently supported.
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
 
Cannot create an instance of TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T] 
because Type.ContainsGenericParameters is true. 
[TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
&lt;/pre&gt; &lt;br /&gt;Not all types in an assembly qualify for automatic testing of constructors or properties. Looking at the errors produced above it is clear that the two first errors are should be fixed (A property which is not mapped correctly and a constructor which does not map correctly to the corresponding property). The last two errors indicates that the AssemblyTester can not test this particular type because it contains generic parameters.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Exclusions
&lt;/h2&gt; &lt;br /&gt;To still use the AssemblyTester on this module we can skip these last two issues. This can be done in two ways, specifying one or more types to exclude or specifying a namespace to exclude. &lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a type
&lt;/h3&gt; &lt;br /&gt;The example excludes the class which is not qualified for automatic testing to the AssemblyTester.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot;);
     tester.Exclusions.AddType(typeof(GenericClass&amp;lt;&amp;gt;));
     tester.TestAssembly(AssemblyTester.TestTarget.Properties | AssemblyTester.TestTarget.Constructors);
&lt;/pre&gt; &lt;br /&gt;When running the test again the AssemblyTester only produces the following errors.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
TheJoyOfCode.QualityTools.AssemblyTestException: Testing the assembly 
TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: '1e5101b5-e9e9-4d69-b13c-83863f70a7b6')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: '2bf2002e-b505-4413-a8f9-97036c40f720', out: '8a447a00-2f17-4d27-bb25-1fc66bf2c39d')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
&lt;/pre&gt; &lt;br /&gt;The errors above are errors which the AssemblyTester has been designed to detect; errors in mapping properties to fields and mapping values to constructors. So to make the test pass we need to fix those errors!&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a namespace
&lt;/h3&gt; &lt;br /&gt;The example below excludes all types in the namepace &amp;quot;ExampleAssembly.SomeNamespace&amp;quot; namespace &lt;b&gt;but does not exclude types in any sub namespaces.&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
&lt;/pre&gt; &lt;br /&gt;We could specify that all types within a numespace and sub-namespaces are excluded like so:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, true);
&lt;/pre&gt; &lt;br /&gt;For example, this would also exclude any type in the &amp;quot;ExampleAssembly.SomeNamespace.SomeSubNamespace&amp;quot; too.&lt;br /&gt; &lt;br /&gt;You can have as many exclusions as you like and can combine type exclusions with namespace exclusions. Easy peasy.&lt;br /&gt; &lt;br /&gt;If you need to exclude a type from an assembly test because of one &lt;i&gt;funky&lt;/i&gt; property or constructor you can always target that type directly with the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; or &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and exclude the property/type specifically. Best of both worlds.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Adding your own exclusion rules
&lt;/h2&gt;It's easy to extend the exclusion policies available in the AssemblyTester by creating your own class that inherits from TestExclusion. Imagine you want to be able to exclude any class that starts with the letter 'S'. First we need a new &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private class StartsWithSExclusion : TestExclusion
{
    public override bool IsExcluded(Type type)
    {
        return type.Name.StartsWith(&amp;quot;S&amp;quot;);
    }
}
&lt;/pre&gt; &lt;br /&gt;Now we just have to add that type to the Exclusions as follows:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.Add(new StartsWithSExclusion());
&lt;/pre&gt; &lt;br /&gt;... and any types whose name starts with an S won't be tested.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
FAQ
&lt;/h2&gt; &lt;br /&gt;&lt;b&gt;Q:&lt;/b&gt; It's nice that I can exclude whole types and namespaces using the AssemblyTester but why can't I specify a single property on a type that should be excluded.&lt;br /&gt;&lt;b&gt;A:&lt;/b&gt; This feature is deliberately not included to date. The practice in this case is to exclude the type from the assembly test like so:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTester tester = new AssemblyTester(&amp;quot;MyType, MyAssembly&amp;quot;);
tester.Exclusions.AddType(typeof(TypeWithUntestableProperty));
tester.TestAssembly(true, true);
&lt;/pre&gt; &lt;br /&gt;And add another test to target that class using the PropertyTester&lt;br /&gt; &lt;br /&gt;/// TODO + unfinished + &lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Wed, 09 Jan 2008 15:35:04 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: AssemblyTester 20080109033504P</guid></item><item><title>UPDATED WIKI: TypeFactory</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;version=6</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.TypeFactory
&lt;/h1&gt; &lt;br /&gt;The current version of the TypeFactory supports creation of the following types. The TypeFactory tries to create &lt;b&gt;random values&lt;/b&gt; for each type where possible.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Boolean&lt;/li&gt;&lt;li&gt;Byte&lt;/li&gt;&lt;li&gt;Char&lt;/li&gt;&lt;li&gt;DateTime&lt;/li&gt;&lt;li&gt;Decimal&lt;/li&gt;&lt;li&gt;Double&lt;/li&gt;&lt;li&gt;Int16&lt;/li&gt;&lt;li&gt;Int32&lt;/li&gt;&lt;li&gt;Int64&lt;/li&gt;&lt;li&gt;SByte&lt;/li&gt;&lt;li&gt;Single&lt;/li&gt;&lt;li&gt;String&lt;/li&gt;&lt;li&gt;UInt16&lt;/li&gt;&lt;li&gt;UInt32&lt;/li&gt;&lt;li&gt;UInt64&lt;/li&gt;&lt;li&gt;Guid&lt;/li&gt;&lt;li&gt;TimeSpan&lt;/li&gt;&lt;li&gt;Enums&lt;/li&gt;&lt;li&gt;NullableTypes (where a value type in this list)&lt;/li&gt;&lt;li&gt;Type (a random type is compiled at runtime using the codedom)&lt;/li&gt;&lt;li&gt;Types with a default constructors&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The most notable limitations are are abstract classes (including interfaces), arrays and classes with non-default constructors. If you'd like these features please vote for these features here: &lt;a href="http://www.codeplex.com/classtester/WorkItem/List.aspx" class="externalLink"&gt;Work Items&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 14:42:48 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TypeFactory 20080104024248P</guid></item><item><title>UPDATED WIKI: TypeFactory</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.TypeFactory
&lt;/h1&gt; &lt;br /&gt;The current version of the TypeFactory supports creation of the following types. The TypeFactory tries to create &lt;b&gt;random values&lt;/b&gt; for each type where possible.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Boolean&lt;/li&gt;&lt;li&gt;Byte&lt;/li&gt;&lt;li&gt;Char&lt;/li&gt;&lt;li&gt;DateTime&lt;/li&gt;&lt;li&gt;Decimal&lt;/li&gt;&lt;li&gt;Double&lt;/li&gt;&lt;li&gt;Int16&lt;/li&gt;&lt;li&gt;Int32&lt;/li&gt;&lt;li&gt;Int64&lt;/li&gt;&lt;li&gt;SByte&lt;/li&gt;&lt;li&gt;Single&lt;/li&gt;&lt;li&gt;String&lt;/li&gt;&lt;li&gt;UInt16&lt;/li&gt;&lt;li&gt;UInt32&lt;/li&gt;&lt;li&gt;UInt64&lt;/li&gt;&lt;li&gt;Guid&lt;/li&gt;&lt;li&gt;Enums&lt;/li&gt;&lt;li&gt;NullableTypes (where a value type in this list)&lt;/li&gt;&lt;li&gt;Type (a random type is compiled at runtime using the codedom)&lt;/li&gt;&lt;li&gt;Types with a default constructors&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The most notable limitations are are abstract classes (including interfaces), arrays and classes with non-default constructors. If you'd like these features please vote for these features here: &lt;a href="http://www.codeplex.com/classtester/WorkItem/List.aspx" class="externalLink"&gt;Work Items&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 14:42:33 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TypeFactory 20080104024233P</guid></item><item><title>UPDATED WIKI: AssemblyTester</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
The AssemblyTester
&lt;/h1&gt; &lt;br /&gt;The AssemblyTester uses the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; and &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and can remove much of the coding previously required to use them by applying these tests to all the types in an assembly, subject to exclusions that you can specify.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
How it works
&lt;/h3&gt; &lt;br /&gt;To test an assembly simply create an instance of the AssemblyTester passing it the name of the Assembly to test.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools&amp;quot;);
&lt;/pre&gt; &lt;br /&gt;Now you can call the AssemblyTesters TestAssembly method which looks like this:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     public void TestAssembly(bool testProperties, bool testConstructors)
&lt;/pre&gt; &lt;br /&gt;The testProperties and testConstructors parameters should be fairly self explanatory!&lt;br /&gt; &lt;br /&gt;The example below aims to test both constructors and properties in the &amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot; assembly.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
     tester.TestAssembly(true, true);
&lt;/pre&gt; &lt;br /&gt;The AssemblyTester will throw an exception with a detailed description of errors encountered when testing an assembly. Here's an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTesterTest.AssemblyTester_PassWithExclusions : FailedTheJoyOfCode.QualityTools.AssemblyTestException: 
Testing the assembly TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: 'fe6faacc-3ea8-45a0-8c5c-dc2e0021065b')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: 'cf04ca44-73dc-4147-bb3e-2a1a0d2c52b3', out: '819e635d-4dc6-4e6c-b141-75f0212cb242')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
 
The type TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1 is an open 
Generic Definition (e.g. Class&amp;lt;T&amp;gt;. Only closed generic types Class&amp;lt;int&amp;gt; are currently supported.
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
 
Cannot create an instance of TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T] 
because Type.ContainsGenericParameters is true. 
[TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
&lt;/pre&gt; &lt;br /&gt;Not all types in an assembly qualify for automatic testing of constructors or properties. Looking at the errors produced above it is clear that the two first errors are should be fixed (A property which is not mapped correctly and a constructor which does not map correctly to the corresponding property). The last two errors indicates that the AssemblyTester can not test this particular type because it contains generic parameters.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Exclusions
&lt;/h2&gt; &lt;br /&gt;To still use the AssemblyTester on this module we can skip these last two issues. This can be done in two ways, specifying one or more types to exclude or specifying a namespace to exclude. &lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a type
&lt;/h3&gt; &lt;br /&gt;The example excludes the class which is not qualified for automatic testing to the AssemblyTester.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot;);
     tester.Exclusions.AddType(typeof(GenericClass&amp;lt;&amp;gt;));
     tester.TestAssembly(AssemblyTester.TestTarget.Properties | AssemblyTester.TestTarget.Constructors);
&lt;/pre&gt; &lt;br /&gt;When running the test again the AssemblyTester only produces the following errors.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
TheJoyOfCode.QualityTools.AssemblyTestException: Testing the assembly 
TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: '1e5101b5-e9e9-4d69-b13c-83863f70a7b6')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: '2bf2002e-b505-4413-a8f9-97036c40f720', out: '8a447a00-2f17-4d27-bb25-1fc66bf2c39d')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
&lt;/pre&gt; &lt;br /&gt;The errors above are errors which the AssemblyTester has been designed to detect; errors in mapping properties to fields and mapping values to constructors. So to make the test pass we need to fix those errors!&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a namespace
&lt;/h3&gt; &lt;br /&gt;The example below excludes all types in the namepace &amp;quot;ExampleAssembly.SomeNamespace&amp;quot; namespace &lt;b&gt;but does not exclude types in any sub namespaces.&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
&lt;/pre&gt; &lt;br /&gt;We could specify that all types within a numespace and sub-namespaces are excluded like so:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, true);
&lt;/pre&gt; &lt;br /&gt;For example, this would also exclude any type in the &amp;quot;ExampleAssembly.SomeNamespace.SomeSubNamespace&amp;quot; too.&lt;br /&gt; &lt;br /&gt;You can have as many exclusions as you like and can combine type exclusions with namespace exclusions. Easy peasy.&lt;br /&gt; &lt;br /&gt;If you need to exclude a type from an assembly test because of one &lt;i&gt;funky&lt;/i&gt; property or constructor you can always target that type directly with the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; or &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and exclude the property/type specifically. Best of both worlds.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Adding your own exclusion rules
&lt;/h2&gt;It's easy to extend the exclusion policies available in the AssemblyTester by creating your own class that inherits from TestExclusion. Imagine you want to be able to exclude any class that starts with the letter 'S'. First we need a new &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private class StartsWithSExclusion : TestExclusion
{
    public override bool IsExcluded(Type type)
    {
        return type.Name.StartsWith(&amp;quot;S&amp;quot;);
    }
}
&lt;/pre&gt; &lt;br /&gt;Now we just have to add that type to the Exclusions as follows:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.Add(new StartsWithSExclusion());
&lt;/pre&gt; &lt;br /&gt;... any any types whose name starts with an S won't be tested.&lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 14:03:39 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: AssemblyTester 20080104020339P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home&amp;version=22</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Welcome to the Class Tester
&lt;/h1&gt;This project started life as a blog post and some source code (read the &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;original post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;) 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:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt;! (formerly the ClassTester)&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt;! (formerly part of the ClassTester)&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Click the links above for more information on each of the pieces.&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;The idea is pretty simple - a way to easily test your domain classes. You know, the plain old data shapes that look something like this: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;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).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
&lt;i&gt;Something had to be done and the Automatic Class Tester project was born!&lt;/i&gt;
&lt;/h2&gt;&lt;h2&gt;
What it can do:
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Automatically test properties, spotting any miswired getters or setters &lt;/li&gt;&lt;li&gt;Increase code coverage, reaching parts manual tests don't even try to &lt;/li&gt;&lt;li&gt;Supports ignoring specified properties if you have any funky logic in there that needs a manual test &lt;/li&gt;&lt;li&gt;Tests for PropertyChanged events if your class implements INotifyPropertyChanged &lt;/li&gt;&lt;li&gt;Tests constructors and that they map parameters to properties &lt;/li&gt;&lt;li&gt;An exception is thrown when a problem is found which should cause your tests to fail. &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h2&gt;
How it works
&lt;/h2&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; for more information... &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    ClassTester tester = new ClassTester(new Person());
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private int _nonsensicalProperty;
 
public DateTime NonsensicalProperty
{
    get { return 0; }
    set { _nonsensicalProperty = value; }
}
&lt;/pre&gt; &lt;br /&gt;No problem, we can still use the tester by specifying that this property should be ignored. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;NonsensicalProperty&amp;quot;);
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;This is perhaps the most compelling use of the tester given how easy it is to mess up firing the INotifyPropertyChanged due to the lack of compile time support (it's based on strings). &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
 
    // etc..
&lt;/pre&gt; &lt;br /&gt;Again, if a specific property doesn't support INotifyPropertyChanged for some reason, then just add it to the ignored list and test it manually. &lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Testing Constructors
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        _name = name;    
    }
    
    // etc
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Testing whole assemblies
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;To help you test large numbers of classes at once there is even an assembly tester that will test all the properties and constructors, of all the classes.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void AssemblyTester_PassWithExclusions()
{
    AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
    // exclude a namespace from the test scope but not child namespaces
    tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
    // first parameters says test properties, second parameter says test constructors
    tester.TestAssembly(true, true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Remember kids!&lt;/b&gt; 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. &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 13:06:26 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080104010626P</guid></item><item><title>UPDATED WIKI: TypeFactory</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.TypeFactory
&lt;/h1&gt; &lt;br /&gt;The current version of the TypeFactory supports creation of the following types. The TypeFactory tries to create &lt;b&gt;random values&lt;/b&gt; for each type where possible.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Boolean&lt;/li&gt;&lt;li&gt;Byte&lt;/li&gt;&lt;li&gt;Char&lt;/li&gt;&lt;li&gt;DateTime&lt;/li&gt;&lt;li&gt;Decimal&lt;/li&gt;&lt;li&gt;Double&lt;/li&gt;&lt;li&gt;Int16&lt;/li&gt;&lt;li&gt;Int32&lt;/li&gt;&lt;li&gt;Int64&lt;/li&gt;&lt;li&gt;SByte&lt;/li&gt;&lt;li&gt;Single&lt;/li&gt;&lt;li&gt;String&lt;/li&gt;&lt;li&gt;UInt16&lt;/li&gt;&lt;li&gt;UInt32&lt;/li&gt;&lt;li&gt;UInt64&lt;/li&gt;&lt;li&gt;Guid&lt;/li&gt;&lt;li&gt;Enums&lt;/li&gt;&lt;li&gt;NullableTypes (where a value type in this list)&lt;/li&gt;&lt;li&gt;Type (a random type is compiled at runtime using the codedom)&lt;/li&gt;&lt;li&gt;Types with a default constructors&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The most notable limitations are are abstract classes (including interfaces) and classes with non-default constructors. If you'd like these features please vote for these features here: &lt;a href="http://www.codeplex.com/classtester/WorkItem/List.aspx" class="externalLink"&gt;Work Items&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 13:04:26 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TypeFactory 20080104010426P</guid></item><item><title>UPDATED WIKI: ConstructorTester</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.ConstructorTester
&lt;/h1&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        Name = name;    
    }
 
    public string Name { get; set; }
    public string DateOfBirth { get; set; }
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(false);
}
&lt;/pre&gt; &lt;br /&gt;This static method will test all constructors available on the object by creating random values using the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;amp;referringTitle=ConstructorTester"&gt;TypeFactory&lt;/a&gt; (follow the link for supported types). Obviously, in this basic example no logic is validated the constructor is just called and if no exception is raised your test will pass.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Mapped properties.
&lt;/h2&gt;The TestConstructors method has a testMappedProperties parameter which, if set to true, will test that any properties on the new object that have a namesake on the constructor (case insensitive matching) have the same value that was injected at construction.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;In this case our test will fail because our example object above takes a dateOfBirth parameter at construction and has a DateOfBirth property but this property is never wired up. The resulting ConstructorTestException would have the following message: &lt;span class="codeInline"&gt;&amp;quot;The value of the 'DateOfBirth' property did not equal the value set with the 'dateOfBirth' constructor parameter (in: '2007-09-22', out: '1900-01-01')&amp;quot;&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Exclusions
&lt;/h2&gt;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 &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;amp;referringTitle=ConstructorTester"&gt;TypeFactory&lt;/a&gt; can't create.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 12:57:11 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: ConstructorTester 20080104125711P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home&amp;version=21</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Welcome to the Class Tester
&lt;/h1&gt;This project started life as a blog post and some source code (read the &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;original post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;) 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:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt;! (formerly the ClassTester)&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt;! (formerly part of the ClassTester)&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Click the links above for more information on each of the pieces.&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;The idea is pretty simple - a way to easily test your domain classes. You know, the plain old data shapes that look something like this: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;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).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
&lt;i&gt;Something had to be done and the Automatic Class Tester project was born!&lt;/i&gt;
&lt;/h2&gt;&lt;h2&gt;
What it can do:
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Automatically test properties, spotting any miswired getters or setters &lt;/li&gt;&lt;li&gt;Increase code coverage, reaching parts manual tests don't even try to &lt;/li&gt;&lt;li&gt;Supports ignoring specified properties if you have any funky logic in there that needs a manual test &lt;/li&gt;&lt;li&gt;Tests for PropertyChanged events if your class implements INotifyPropertyChanged &lt;/li&gt;&lt;li&gt;Tests constructors and that they map parameters to properties &lt;/li&gt;&lt;li&gt;An exception is thrown when a problem is found which should cause your tests to fail. &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h2&gt;
How it works
&lt;/h2&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; for more information... &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    ClassTester tester = new ClassTester(new Person());
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private int _nonsensicalProperty;
 
public DateTime NonsensicalProperty
{
    get { return 0; }
    set { _nonsensicalProperty = value; }
}
&lt;/pre&gt; &lt;br /&gt;No problem, we can still use the tester by specifying that this property should be ignored. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;NonsensicalProperty&amp;quot;);
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;This is perhaps the most compelling use of the tester given how easy it is to mess up firing the INotifyPropertyChanged due to the lack of compile time support (it's based on strings). &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
 
    // etc..
&lt;/pre&gt; &lt;br /&gt;Again, if a specific property doesn't support INotifyPropertyChanged for some reason, then just add it to the ignored list and test it manually. &lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Testing Constructors
&lt;/h2&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        _name = name;    
    }
    
    // etc
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Testing whole assemblies
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;To help you test large numbers of classes at once there is even an assembly tester that will test all the properties and constructors, of all the classes.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void AssemblyTester_PassWithExclusions()
{
    AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
    // exclude a namespace from the test scope but not child namespaces
    tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
    // first parameters says test properties, second parameter says test constructors
    tester.TestAssembly(true, true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Remember kids!&lt;/b&gt; 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 exlude a namespace, type, property or constructor then you should consider adding a manual test. &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 12:47:23 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080104124723P</guid></item><item><title>UPDATED WIKI: PropertyTester</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.PropertyTester
&lt;/h1&gt; &lt;br /&gt;The PropertyTester (formerly known as the ClassTester) automatically tests properties by calling the set and get methods and ensuring that the same value is returned. If the property is a &lt;b&gt;set&lt;/b&gt; only or &lt;b&gt;get&lt;/b&gt; only then this check can't be made but the set and get will be called.&lt;br /&gt; &lt;br /&gt;Here's an example object that might be targetted with such a test:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    public double AgeInDays
    {
         get {  return (DateTime.Today.Subtract(_dateOfBirth).TotalDays);  }
    }
 
    private ISomeProvider _provider
 
    public ISomeProvider Provider
    {
        get { return _provider; }
        set { _provider= value; }
    }
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;Which could be tested like so.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
   PropertyTester tester = new PropertyTester(new Person());
   tester.TestProperties();
&lt;/pre&gt; &lt;br /&gt;This would give great coverage of this class testing Name, DateOfBirth and AgeInDays properties with only one problem...&lt;br /&gt; &lt;br /&gt;Obviously, to call &lt;b&gt;set&lt;/b&gt; the PropertyTester must create a type to pass as a value. It has a TypeFactory to support the creation of types but there are limitations to the types that it can create. For more information see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;amp;referringTitle=PropertyTester"&gt;TypeFactory&lt;/a&gt;. The most obvious limitations are abstract classes (including interfaces) and classes with non-default constructors.&lt;br /&gt; &lt;br /&gt;     &lt;b&gt;Note:&lt;/b&gt; The functionality in the AgeInDays property is &lt;b&gt;NOT&lt;/b&gt; validated by the PropertyTester and we'd recommend you test this using a seperate, manual unit test.&lt;br /&gt; &lt;br /&gt;If you try to TestProperties() on a Class that exposes a property of an unsupported type (like our ISomeProvider type) you will get a PropertyTestException thrown with a message along the lines of:&lt;br /&gt; &lt;br /&gt;&lt;span class="codeInline"&gt; &amp;quot;Cannot generate type 'ISomeProvider' to set on property 'Provider'. Consider ignoring this property on the type 'Person'&amp;quot; &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;This doesn't mean that you can't use the PropertyTester with this type, we just need to exclude that particular property.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Exclusions
&lt;/h2&gt;It's easy to exclude a property from the test:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;Provider&amp;quot;);
    tester.TestProperties();
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;One of the key motivations for creating the original &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;ClassTester&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; was to test that classes implementing INotifyPropertyChanged fire the correct events appropriately. Here's an example implementation:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
&lt;/pre&gt; &lt;br /&gt;As you can imagine, authoring such classes is error prone and therefore testing this functionality is important.&lt;br /&gt; &lt;br /&gt;The PropertyTester automatically inspects classes to see if they implement INotifyPropertyChanged and verifies that PropertyChangedEvents are raised when the value of the property changes. &lt;br /&gt; &lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; The PropertyTester will try to set the value once and then set it again with a &lt;b&gt;different&lt;/b&gt; value to test for PropertyChangedEvents (because you may implement INotifyPropertyChanged to only fire if the value actually changes!). Therefore, if the TypeFactory can't generate two different random values you will get a PropertyTestException: &amp;quot;Could not generate two different values for the type 'SomeType'. Consider ignoring the 'YourProperty' property on the type 'YourType' or increasing the MaxLoopsPerProperty value above 1000&amp;quot;.&lt;br /&gt;                                &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 12:46:07 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PropertyTester 20080104124607P</guid></item><item><title>UPDATED WIKI: TypeFactory</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.TypeFactory
&lt;/h1&gt; &lt;br /&gt;The current version of the TypeFactory supports creation of the following types. The TypeFactory tries to create &lt;b&gt;random values&lt;/b&gt; for each type where possible.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Boolean&lt;/li&gt;&lt;li&gt;Byte&lt;/li&gt;&lt;li&gt;Char&lt;/li&gt;&lt;li&gt;DateTime&lt;/li&gt;&lt;li&gt;Decimal&lt;/li&gt;&lt;li&gt;Double&lt;/li&gt;&lt;li&gt;Int16&lt;/li&gt;&lt;li&gt;Int32&lt;/li&gt;&lt;li&gt;Int64&lt;/li&gt;&lt;li&gt;SByte&lt;/li&gt;&lt;li&gt;Single&lt;/li&gt;&lt;li&gt;String&lt;/li&gt;&lt;li&gt;UInt16&lt;/li&gt;&lt;li&gt;UInt32&lt;/li&gt;&lt;li&gt;UInt64&lt;/li&gt;&lt;li&gt;Guid&lt;/li&gt;&lt;li&gt;Enums&lt;/li&gt;&lt;li&gt;NullableTypes (where a value type in this list)&lt;/li&gt;&lt;li&gt;Type (a random type is compiled at runtime using the codedom)&lt;/li&gt;&lt;li&gt;Types with a default constructors&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 12:36:04 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TypeFactory 20080104123604P</guid></item><item><title>UPDATED WIKI: TypeFactory</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.TypeFactory
&lt;/h1&gt; &lt;br /&gt;The current version of the TypeFactory supports creation of the following types. The TypeFactory tries to create &lt;b&gt;random values&lt;/b&gt; for each type where possible.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Boolean&lt;/li&gt;&lt;li&gt;Byte&lt;/li&gt;&lt;li&gt;Char&lt;/li&gt;&lt;li&gt;DateTime&lt;/li&gt;&lt;li&gt;Decimal&lt;/li&gt;&lt;li&gt;Double&lt;/li&gt;&lt;li&gt;Int16&lt;/li&gt;&lt;li&gt;Int32&lt;/li&gt;&lt;li&gt;Int64&lt;/li&gt;&lt;li&gt;SByte&lt;/li&gt;&lt;li&gt;Single&lt;/li&gt;&lt;li&gt;String&lt;/li&gt;&lt;li&gt;UInt16&lt;/li&gt;&lt;li&gt;UInt32&lt;/li&gt;&lt;li&gt;UInt64&lt;/li&gt;&lt;li&gt;Guid&lt;/li&gt;&lt;li&gt;Enums&lt;/li&gt;&lt;li&gt;NullableTypes (where a value type in this list)&lt;/li&gt;&lt;li&gt;Type (a random type is compiled at runtime using the codedom)&lt;/li&gt;&lt;li&gt;Types with a default constructors&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 12:33:53 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TypeFactory 20080104123353P</guid></item><item><title>UPDATED WIKI: TypeFactory</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
!TheJoyOfCode.QualityTools.TypeFactory&lt;br /&gt; &lt;br /&gt;The current version of the TypeFactory supports creation of the following types. The TypeFactory tries to create &lt;b&gt;random values&lt;/b&gt; for each type where possible.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Boolean&lt;/li&gt;&lt;li&gt;Byte&lt;/li&gt;&lt;li&gt;Char&lt;/li&gt;&lt;li&gt;DateTime&lt;/li&gt;&lt;li&gt;Decimal&lt;/li&gt;&lt;li&gt;Double&lt;/li&gt;&lt;li&gt;Int16&lt;/li&gt;&lt;li&gt;Int32&lt;/li&gt;&lt;li&gt;Int64&lt;/li&gt;&lt;li&gt;SByte&lt;/li&gt;&lt;li&gt;Single&lt;/li&gt;&lt;li&gt;String&lt;/li&gt;&lt;li&gt;UInt16&lt;/li&gt;&lt;li&gt;UInt32&lt;/li&gt;&lt;li&gt;UInt64&lt;/li&gt;&lt;li&gt;Guid&lt;/li&gt;&lt;li&gt;Enums&lt;/li&gt;&lt;li&gt;NullableTypes (where a value type in this list)&lt;/li&gt;&lt;li&gt;Type (a random type is compiled at runtime using the codedom)&lt;/li&gt;&lt;li&gt;Types with a default constructors&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 12:32:22 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TypeFactory 20080104123222P</guid></item><item><title>UPDATED WIKI: PropertyTester</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
TheJoyOfCode.QualityTools.PropertyTester
&lt;/h1&gt; &lt;br /&gt;The PropertyTester (formerly known as the ClassTester) automatically tests properties by calling the set and get methods and ensuring that the same value is returned. If the property is a &lt;b&gt;set&lt;/b&gt; only or &lt;b&gt;get&lt;/b&gt; only then this check can't be made but the set and get will be called.&lt;br /&gt; &lt;br /&gt;Here's an example object that might be targetted with such a test:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    public double AgeInDays
    {
         get {  return (DateTime.Today.Subtract(_dateOfBirth).TotalDays);  }
    }
 
    private ISomeProvider _provider
 
    public ISomeProvider Provider
    {
        get { return _provider; }
        set { _provider= value; }
    }
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;Which could be tested like so.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
   PropertyTester tester = new PropertyTester(new Person());
   tester.TestProperties();
&lt;/pre&gt; &lt;br /&gt;This would give great coverage of this class testing Name, DateOfBirth and AgeInDays properties with only one problem...&lt;br /&gt; &lt;br /&gt;Obviously, to call &lt;b&gt;set&lt;/b&gt; the PropertyTester must create a type to pass as a value. It has a TypeFactory to support the creation of types but there are limitations to the types that it can create. For more information see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=TypeFactory&amp;amp;referringTitle=PropertyTester"&gt;TypeFactory&lt;/a&gt;. The most obvious limitations are abstract classes (including interfaces) and classes with non-default constructors.&lt;br /&gt; &lt;br /&gt;If you try to TestProperties() on a Class that exposes a property of an unsupported type (like our ISomeProvider type) you will get a PropertyTestException thrown with a message along the lines of:&lt;br /&gt; &lt;br /&gt;&lt;span class="codeInline"&gt; &amp;quot;Cannot generate type 'ISomeProvider' to set on property 'Provider'. Consider ignoring this property on the type 'Person'&amp;quot; &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;This doesn't mean that you can't use the PropertyTester with this type, we just need to exclude that particular property.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Exclusions
&lt;/h2&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Fri, 04 Jan 2008 12:27:13 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PropertyTester 20080104122713P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home&amp;version=20</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Welcome to the Class Tester
&lt;/h1&gt;This project started life as a blog post and some source code (read the &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;original post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;) 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:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt;! (formerly the ClassTester)&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt;! (formerly part of the ClassTester)&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Click the links above for more information on each of the pieces.&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;The idea is pretty simple - a way to easily test your domain classes. You know, the plain old data shapes that look something like this: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;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).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
&lt;i&gt;Something had to be done and the Automatic Class Tester project was born!&lt;/i&gt;
&lt;/h2&gt;&lt;h2&gt;
What it can do:
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Automatically test properties, spotting any miswired getters or setters &lt;/li&gt;&lt;li&gt;Increase code coverage, reaching parts manual tests don't even try to &lt;/li&gt;&lt;li&gt;Supports ignoring specified properties if you have any funky logic in there that needs a manual test &lt;/li&gt;&lt;li&gt;Tests for PropertyChanged events if your class implements INotifyPropertyChanged &lt;/li&gt;&lt;li&gt;Tests constructors and that they map parameters to properties &lt;/li&gt;&lt;li&gt;An exception is thrown when a problem is found which should cause your tests to fail. &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h2&gt;
How it works
&lt;/h2&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; for more information... &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    ClassTester tester = new ClassTester(new Person());
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private int _nonsensicalProperty;
 
public DateTime NonsensicalProperty
{
    get { return 0; }
    set { _nonsensicalProperty = value; }
}
&lt;/pre&gt; &lt;br /&gt;No problem, we can still use the tester by specifying that this property should be ignored. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;NonsensicalProperty&amp;quot;);
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;This is perhaps the most compelling use of the tester given how easy it is to mess up firing the INotifyPropertyChanged due to the lack of compile time support (it's based on strings). &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
 
    // etc..
&lt;/pre&gt; &lt;br /&gt;Again, if a specific property doesn't support INotifyPropertyChanged for some reason, then just add it to the ignored list and test it manually. &lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Testing Constructors
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        _name = name;    
    }
    
    // etc
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Testing whole assemblies
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;To help you test large numbers of classes at once there is even an assembly tester that will test all the properties and constructors, of all the classes.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void AssemblyTester_PassWithExclusions()
{
    AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
    // exclude a namespace from the test scope but not child namespaces
    tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
    // first parameters says test properties, second parameter says test constructors
    tester.TestAssembly(true, true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Remember kids!&lt;/b&gt; 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 exlude a namespace, type, property or constructor then you should consider adding a manual test. &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Thu, 03 Jan 2008 17:44:12 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080103054412P</guid></item><item><title>UPDATED WIKI: AssemblyTester</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
The AssemblyTester
&lt;/h1&gt; &lt;br /&gt;The AssemblyTester uses the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; and &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and can remove much of the coding previously required to use them by applying these tests to all the types in an assembly, subject to exclusions that you can specify.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
How it works
&lt;/h3&gt; &lt;br /&gt;To test an assembly simply create an instance of the AssemblyTester passing it the name of the Assembly to test.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools&amp;quot;);
&lt;/pre&gt; &lt;br /&gt;Now you can call the AssemblyTesters TestAssembly method which looks like this:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     public void TestAssembly(bool testProperties, bool testConstructors)
&lt;/pre&gt; &lt;br /&gt;The testProperties and testConstructors parameters should be fairly self explanatory!&lt;br /&gt; &lt;br /&gt;The example below aims to test both constructors and properties in the &amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot; assembly.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
     tester.TestAssembly(true, true);
&lt;/pre&gt; &lt;br /&gt;The AssemblyTester will throw an exception with a detailed description of errors encountered when testing an assembly. Here's an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
AssemblyTesterTest.AssemblyTester_PassWithExclusions : FailedTheJoyOfCode.QualityTools.AssemblyTestException: 
Testing the assembly TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: 'fe6faacc-3ea8-45a0-8c5c-dc2e0021065b')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: 'cf04ca44-73dc-4147-bb3e-2a1a0d2c52b3', out: '819e635d-4dc6-4e6c-b141-75f0212cb242')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
 
The type TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1 is an open 
Generic Definition (e.g. Class&amp;lt;T&amp;gt;. Only closed generic types Class&amp;lt;int&amp;gt; are currently supported.
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
 
Cannot create an instance of TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T] 
because Type.ContainsGenericParameters is true. 
[TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.GenericClass`1[T]]
&lt;/pre&gt; &lt;br /&gt;Not all types in an assembly qualify for automatic testing of constructors or properties. Looking at the errors produced above it is clear that the two first errors are should be fixed (A property which is not mapped correctly and a constructor which does not map correctly to the corresponding property). The last two errors indicates that the AssemblyTester can not test this particular type because it contains generic parameters.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Exclusions
&lt;/h2&gt; &lt;br /&gt;To still use the AssemblyTester on this module we can skip these last two issues. This can be done in two ways, specifying one or more types to exclude or specifying a namespace to exclude. &lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a type
&lt;/h3&gt; &lt;br /&gt;The example excludes the class which is not qualified for automatic testing to the AssemblyTester.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     AssemblyTester tester = new AssemblyTester(&amp;quot;TheJoyOfCode.QualityTools.Tests.DummyProject&amp;quot;);
     tester.Exclusions.AddType(typeof(GenericClass&amp;lt;&amp;gt;));
     tester.TestAssembly(AssemblyTester.TestTarget.Properties | AssemblyTester.TestTarget.Constructors);
&lt;/pre&gt; &lt;br /&gt;When running the test again the AssemblyTester only produces the following errors.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
TheJoyOfCode.QualityTools.AssemblyTestException: Testing the assembly 
TheJoyOfCode.QualityTools.Tests.DummyProject produced the following errors:
------------
The get value of the 'Dummy4' property on the type 'TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties' 
did not equal the set value (in: '', out: '1e5101b5-e9e9-4d69-b13c-83863f70a7b6')
 [TestProperties,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectProperties]
 
The value of the 'Dummy1' property did not equal the value set with the 'dummy1' 
constructor parameter (in: '2bf2002e-b505-4413-a8f9-97036c40f720', out: '8a447a00-2f17-4d27-bb25-1fc66bf2c39d')
 [TestConstructors,Type:TheJoyOfCode.QualityTools.Tests.DummyProject.WithErrors.IncorrectConstructors]
&lt;/pre&gt; &lt;br /&gt;The errors above are errors which the AssemblyTester has been designed to detect; errors in mapping properties to fields and mapping values to constructors. So to make the test pass we need to fix those errors!&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Excluding a namespace
&lt;/h3&gt; &lt;br /&gt;The example below excludes all types in the namepace &amp;quot;ExampleAssembly.SomeNamespace&amp;quot; namespace &lt;b&gt;but does not exclude types in any sub namespaces.&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
&lt;/pre&gt; &lt;br /&gt;We could specify that all types within a numespace and sub-namespaces are excluded like so:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
     tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, true);
&lt;/pre&gt; &lt;br /&gt;For example, this would also exclude any type in the &amp;quot;ExampleAssembly.SomeNamespace.SomeSubNamespace&amp;quot; too.&lt;br /&gt; &lt;br /&gt;You can have as many exclusions as you like and can combine type exclusions with namespace exclusions. Easy peasy.&lt;br /&gt; &lt;br /&gt;If you need to exclude a type from an assembly test because of one &lt;i&gt;funky&lt;/i&gt; property or constructor you can always target that type directly with the &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=AssemblyTester"&gt;PropertyTester&lt;/a&gt; or &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=AssemblyTester"&gt;ConstructorTester&lt;/a&gt; and exclude the property/type specifically. Best of both worlds.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Thu, 03 Jan 2008 17:37:06 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: AssemblyTester 20080103053706P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home&amp;version=19</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Welcome to the Class Tester
&lt;/h1&gt;This project started life as a blog post and some source code (read the &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;original post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;) 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:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt;!&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; (formerly the ClassTester)!&lt;/li&gt;&lt;li&gt;A new and improved &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Click the links above for more information on each of the pieces.&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;The idea is pretty simple - a way to easily test your domain classes. You know, the plain old data shapes that look something like this: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;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).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
&lt;i&gt;Something had to be done and the Automatic Class Tester project was born!&lt;/i&gt;
&lt;/h2&gt;&lt;h2&gt;
What it can do:
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Automatically test properties, spotting any miswired getters or setters &lt;/li&gt;&lt;li&gt;Increase code coverage, reaching parts manual tests don't even try to &lt;/li&gt;&lt;li&gt;Supports ignoring specified properties if you have any funky logic in there that needs a manual test &lt;/li&gt;&lt;li&gt;Tests for PropertyChanged events if your class implements INotifyPropertyChanged &lt;/li&gt;&lt;li&gt;Tests constructors and that they map parameters to properties &lt;/li&gt;&lt;li&gt;An exception is thrown when a problem is found which should cause your tests to fail. &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h2&gt;
How it works
&lt;/h2&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; for more information... &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    ClassTester tester = new ClassTester(new Person());
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private int _nonsensicalProperty;
 
public DateTime NonsensicalProperty
{
    get { return 0; }
    set { _nonsensicalProperty = value; }
}
&lt;/pre&gt; &lt;br /&gt;No problem, we can still use the tester by specifying that this property should be ignored. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;NonsensicalProperty&amp;quot;);
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;This is perhaps the most compelling use of the tester given how easy it is to mess up firing the INotifyPropertyChanged due to the lack of compile time support (it's based on strings). &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
 
    // etc..
&lt;/pre&gt; &lt;br /&gt;Again, if a specific property doesn't support INotifyPropertyChanged for some reason, then just add it to the ignored list and test it manually. &lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Testing Constructors
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        _name = name;    
    }
    
    // etc
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Testing whole assemblies
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;To help you test large numbers of classes at once there is even an assembly tester that will test all the properties and constructors, of all the classes.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void AssemblyTester_PassWithExclusions()
{
    AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
    // exclude a namespace from the test scope but not child namespaces
    tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
    // first parameters says test properties, second parameter says test constructors
    tester.TestAssembly(true, true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Remember kids!&lt;/b&gt; 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 exlude a namespace, type, property or constructor then you should consider adding a manual test. &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Thu, 03 Jan 2008 17:25:04 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080103052504P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home&amp;version=18</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Welcome to the Class Tester
&lt;/h1&gt;This project started life as a blog post and some source code (read the &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;orignal post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;) 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:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt;!&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; (formerly the ClassTester)!&lt;/li&gt;&lt;li&gt;A new and improved &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Click the links above for more information on each of the pieces.&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;The idea is pretty simple - a way to easily test your domain classes. You know, the plain old data shapes that look something like this: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;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).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
&lt;i&gt;Something had to be done and the Automatic Class Tester project was born!&lt;/i&gt;
&lt;/h2&gt;&lt;h2&gt;
What it can do:
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Automatically test properties, spotting any miswired getters or setters &lt;/li&gt;&lt;li&gt;Increase code coverage, reaching parts manual tests don't even try to &lt;/li&gt;&lt;li&gt;Supports ignoring specified properties if you have any funky logic in there that needs a manual test &lt;/li&gt;&lt;li&gt;Tests for PropertyChanged events if your class implements INotifyPropertyChanged &lt;/li&gt;&lt;li&gt;Tests constructors and that they map parameters to properties &lt;/li&gt;&lt;li&gt;An exception is thrown when a problem is found which should cause your tests to fail. &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h2&gt;
How it works
&lt;/h2&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; for more information... &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    ClassTester tester = new ClassTester(new Person());
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private int _nonsensicalProperty;
 
public DateTime NonsensicalProperty
{
    get { return 0; }
    set { _nonsensicalProperty = value; }
}
&lt;/pre&gt; &lt;br /&gt;No problem, we can still use the tester by specifying that this property should be ignored. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;NonsensicalProperty&amp;quot;);
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;This is perhaps the most compelling use of the tester given how easy it is to mess up firing the INotifyPropertyChanged due to the lack of compile time support (it's based on strings). &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
 
    // etc..
&lt;/pre&gt; &lt;br /&gt;Again, if a specific property doesn't support INotifyPropertyChanged for some reason, then just add it to the ignored list and test it manually. &lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Testing Constructors
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        _name = name;    
    }
    
    // etc
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Testing whole assemblies
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;To help you test large numbers of classes at once there is even an assembly tester that will test all the properties and constructors, of all the classes.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void AssemblyTester_PassWithExclusions()
{
    AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
    // exclude a namespace from the test scope but not child namespaces
    tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
    // first parameters says test properties, second parameter says test constructors
    tester.TestAssembly(true, true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Remember kids!&lt;/b&gt; 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 exlude a namespace, type, property or constructor then you should consider adding a manual test. &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Thu, 03 Jan 2008 17:24:15 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080103052415P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home&amp;version=17</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Welcome to the Class Tester
&lt;/h1&gt;This project started life as a blog post and some source code (read the &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;orignal post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;) 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:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt;!&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; (formerly the ClassTester)!&lt;/li&gt;&lt;li&gt;A new and improved &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Click the links above for more information on each of the pieces.&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;The idea is pretty simple - a way to easily test your domain classes. You know, the plain old data shapes that look something like this: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;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).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
&lt;i&gt;Something had to be done and the ClassTester was born.&lt;/i&gt;
&lt;/h2&gt;&lt;h2&gt;
What it can do:
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Automatically test properties, spotting any miswired getters or setters &lt;/li&gt;&lt;li&gt;Increase code coverage, reaching parts manual tests don't even try to &lt;/li&gt;&lt;li&gt;Supports ignoring specified properties if you have any funky logic in there that needs a manual test &lt;/li&gt;&lt;li&gt;Tests for PropertyChanged events if your class implements INotifyPropertyChanged &lt;/li&gt;&lt;li&gt;Tests constructors and that they map parameters to properties &lt;/li&gt;&lt;li&gt;An exception is thrown when a problem is found which should cause your tests to fail. &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h2&gt;
How it works
&lt;/h2&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; for more information... &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    ClassTester tester = new ClassTester(new Person());
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private int _nonsensicalProperty;
 
public DateTime NonsensicalProperty
{
    get { return 0; }
    set { _nonsensicalProperty = value; }
}
&lt;/pre&gt; &lt;br /&gt;No problem, we can still use the tester by specifying that this property should be ignored. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;NonsensicalProperty&amp;quot;);
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;This is perhaps the most compelling use of the tester given how easy it is to mess up firing the INotifyPropertyChanged due to the lack of compile time support (it's based on strings). &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
 
    // etc..
&lt;/pre&gt; &lt;br /&gt;Again, if a specific property doesn't support INotifyPropertyChanged for some reason, then just add it to the ignored list and test it manually. &lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Testing Constructors
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        _name = name;    
    }
    
    // etc
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Testing whole assemblies
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;To help you test large numbers of classes at once there is even an assembly tester that will test all the properties and constructors, of all the classes.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void AssemblyTester_PassWithExclusions()
{
    AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
    // exclude a namespace from the test scope but not child namespaces
    tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
    // first parameters says test properties, second parameter says test constructors
    tester.TestAssembly(true, true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Remember kids!&lt;/b&gt; 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 exlude a namespace, type, property or constructor then you should consider adding a manual test. &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Thu, 03 Jan 2008 17:23:46 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080103052346P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/classtester/Wiki/View.aspx?title=Home&amp;version=16</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Welcome to the Class Tester
&lt;/h1&gt;This project started life as a blog post and some source code (read the &lt;a href="http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx" class="externalLink"&gt;orignal post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;) 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:&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt;!&lt;/li&gt;&lt;li&gt;A new &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; (formerly the ClassTester)!&lt;/li&gt;&lt;li&gt;A new and improved &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Click the links above for more information on each of the pieces.&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=PropertyTester&amp;amp;referringTitle=Home"&gt;PropertyTester&lt;/a&gt; for more information... &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The idea is pretty simple - a way to easily test your domain classes. You know, the plain old data shapes that look something like this: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    private DateTime _dateOfBirth;
 
    public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
 
    // etc..
}
&lt;/pre&gt; &lt;br /&gt;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).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Something had to be done and the ClassTester was born. 
&lt;/h2&gt; &lt;br /&gt;&lt;h2&gt;
What it can do:
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Automatically test properties, spotting any miswired getters or setters &lt;/li&gt;&lt;li&gt;Increase code coverage, reaching parts manual tests don't even try to &lt;/li&gt;&lt;li&gt;Supports ignoring specified properties if you have any funky logic in there that needs a manual test &lt;/li&gt;&lt;li&gt;Tests for PropertyChanged events if your class implements INotifyPropertyChanged &lt;/li&gt;&lt;li&gt;Tests constructors and that they map parameters to properties &lt;/li&gt;&lt;li&gt;An exception is thrown when a problem is found which should cause your tests to fail. &lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h2&gt;
How it works
&lt;/h2&gt;The ClassTester 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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    ClassTester tester = new ClassTester(new Person());
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;If the ClassTester fails and throws a ClassTesterException then the test fails. Perfick!&lt;br /&gt;The ClassTester is reasonably type aware but will skip properties with non default types (such as interfaces). It is important to utilise this test in conjunction with a code coverage tool to ensure the bits you think are being tested actually are!!.&lt;br /&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private int _nonsensicalProperty;
 
public DateTime NonsensicalProperty
{
    get { return 0; }
    set { _nonsensicalProperty = value; }
}
&lt;/pre&gt; &lt;br /&gt;No problem, we can still use the tester by specifying that this property should be ignored. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[TestMethod]
public void TestPerson()
{
    PropertyTester tester = new PropertyTester(new Person());
    tester.IgnoredProperties.Add(&amp;quot;NonsensicalProperty&amp;quot;);
    tester.TestProperties();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
INotifyPropertyChanged support
&lt;/h2&gt;This is perhaps the most compelling use of the tester given how easy it is to mess up firing the INotifyPropertyChanged due to the lack of compile time support (it's based on strings). &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person : INotifyPropertyChanged
{
    private string _name;
 
    public string Name
    {
        get { return _name; }
        set 
        { 
            _name = value; 
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(&amp;quot;Name&amp;quot;));
        }
    }
 
    // etc..
&lt;/pre&gt; &lt;br /&gt;Again, if a specific property doesn't support INotifyPropertyChanged for some reason, then just add it to the ignored list and test it manually. &lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Testing Constructors
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;See &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=ConstructorTester&amp;amp;referringTitle=Home"&gt;ConstructorTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;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: &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Person
{
    public Person(string name, DateTime dateOfBirth)
    {
        _name = name;    
    }
    
    // etc
&lt;/pre&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void TestPersonConstructors()
{
    ConstructorTester tester = new ConstructorTester(typeof(Person));
    tester.TestConstructors(true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[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);
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Testing whole assemblies
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;see &lt;a href="http://www.codeplex.com/classtester/Wiki/View.aspx?title=AssemblyTester&amp;amp;referringTitle=Home"&gt;AssemblyTester&lt;/a&gt; for more information&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;To help you test large numbers of classes at once there is even an assembly tester that will test all the properties and constructors, of all the classes.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
[Test]
public void AssemblyTester_PassWithExclusions()
{
    AssemblyTester tester = new AssemblyTester(&amp;quot;ExampleAssembly&amp;quot;);
    // exclude a namespace from the test scope but not child namespaces
    tester.Exclusions.AddNamespace(&amp;quot;ExampleAssembly.SomeNamespace&amp;quot;, false);
    // first parameters says test properties, second parameter says test constructors
    tester.TestAssembly(true, true);
}
&lt;/pre&gt; &lt;br /&gt;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.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Remember kids!&lt;/b&gt; 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 exlude a namespace, type, property or constructor then you should consider adding a manual test. &lt;br /&gt;
&lt;/div&gt;</description><author>molmorg</author><pubDate>Thu, 03 Jan 2008 17:21:40 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080103052140P</guid></item></channel></rss>