So I am really bad about not remembering to make unit tests for new classes that I’ve created. I try my best to adhere to TDD, but sometimes I forget. I’m good about running tests (as it is just one button) So is there a way to scan a namespace for all classes, and check to see if they are derived from a known class.
For instance. I have a Contact class. I have 3 sub classes of Contact (Shipping, Billing, Service) I have a unit test for all 3. Lets say a month from now I decide to derive another class from Contact. I’m super good about remember to run my unit tests, but in this case I would want it to fail just 1 test to remind me to write a unit test for my new contact class. Something like.
[TestMethod, TestCategory("Contact")]
public void TestAllContactsAccountedFor()
{
foreach(class c in theNamespace)
{
bool subclassOfContact = c is Contact;
if (subclassOfContact)
{
bool knownSubclass = (c is CustomerShippingContact) || (c is CustomerBillingContact) || (c is CustomerServiceContact);
Assert.IsTrue(knownSubclass);
}
}
}
this way if I forget to make a test it will fail this test, and then I account for it. Any ideas on this?
You should try Mighty Moose a.k.a. ContinuousTests it actually warns you about untested code and is the only code coverage tool for .NET that is free.