Why autogenerated mstests is bad for you!

ms can generate complete test classes for you that test and access all methods and properties, no matter if they are private or public. Isn’t that awesome? Well no.

Let me do a statement first: I’m not fond of auto-generated code, no matter what it is for.

Why? Because writing code makes you think. You’ll have a better chance to find design error earlier than if you get a lot of stuff generated for you. You also need to know how stuff works. If everything is auto-generated for you, you don’t have to care. Right?

Back to mstests.

Reason 1:
The access to private/protected members/properties is bad for you. If you can’t manage to test those methods/properties through the public API it’s most likely that they can’t be called from your regular application either. Either remove the code that you can’t test or refactor the class.

Reason 2:
The ¬†generated test classes includes one test per method.¬†Inexperienced¬†unit testers might think that it’s enough with one test per method: They either just write one test or includes all the different tests in the same test method. Both of those options make it a lot harder to test and get robust applications.

Reason 3:
Readability.The generated tests is harder to read:

(i’ll post samples here later)

Conclusion: Build all your tests by yourself (it makes you think about your design once more). Remove code that you can’t test through the public interface (or refactor).