Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-generation of .NET unit tests

Is there such a thing as unit test generation? If so...

...does it work well?

...What are the auto generation solutions that are available for .NET?

...are there examples of using a technology like this?

...is this only good for certain types of applications, or could it be used to replace all manually written unit testing?

like image 501
Phobis Avatar asked Sep 26 '08 23:09

Phobis


People also ask

Can unit testing of code be automated?

Unit testing is a software development and testing approach in which the smallest testable parts of an application, called units, are individually and independently tested to see if they are operating properly. Unit testing can be done manually but is usually automated.

Which is better NUnit or MsTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.


2 Answers

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
like image 155
Paul Batum Avatar answered Oct 17 '22 22:10

Paul Batum


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.

like image 22
Jon Limjap Avatar answered Oct 18 '22 00:10

Jon Limjap