Auto-generation of .NET unit tests

Take a look at Pex. Its a Microsoft Research project. From the website:

Pex generates Unit Tests from hand-written Parameterized Unit Tests through Automated Exploratory Testing based on Dynamic Symbolic Execution.

UPDATE for 2019:

As mentioned in the comments, Pex is now called IntelliTest and is a feature of Visual Studio Enterprise Edition. It supports emitting tests in MSTest, MSTest V2, NUnit, and xUnit format and it is extensible so you can use it with other unit test frameworks.

But be aware of the following caveats:

  • Supports only C# code that targets the .NET Framework.
  • Does not support x64 configurations.
  • Available in Visual Studio Enterprise Edition only

I believe there's no point in Unit test generation, as far as TDD goes.

You only make unit tests so that you're sure that you (as a developer) are on track w/ regards to design and specs. Once you start generating tests automatically, it loses that purpose. Sure it would probably mean 100% code coverage, but that coverage would be senseless and empty.

Automated unit tests also mean that your strategy is test-after, which is opposite of TDD's test-before tenet. Again, TDD is not about tests.

That being said I believe MSTest does have an automatic unit-test generation tool -- I was able to use one with VS2005.