views:

902

answers:

9

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?

+13  A: 

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.

Paul Batum
+5  A: 

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.

Jon Limjap
+1  A: 

Visual Studio 2008 (maybe 2005 too, I don't know) will at least do all the busy work for you. It will create a project, test classes and test methods.

That means you can care about the actual logic of test wich can't really be generated in a sensible way.

Maximilian
A: 

I've used NStub to stub out test for my classes. It works fairly well.

hectorsosajr
+1  A: 

I agree with Jon. Certain types of testing, like automated fuzz testing, definitely benefit from automated generation. While you can use the facilities of a unit testing framework to accomplish this, this doesn't accomplish the goals associated with good unit test coverage.

tshak
A: 

I've used tools to generate test cases. I think it works well for higher-level, end-user oriented testing. Stuff that's part of User Acceptance Testing, more so than pure unit testing.

I use the unit test tools for this acceptance testing. It works well.

See Tooling to Build Test Cases.

S.Lott
A: 

There is a commercial product called AgitarOne (www.agitar.com) that automatically generates JUnit test classes.
I haven't used it so can't comment on how useful it is, but if I was doing a Java project at the moment I would be looking at it.

I don't know of a .net equivalent (Agitar did one announce a .net version but AFAIK it never materialised).

Rik Garner
A: 

Selenium generates unit tests from user commands on a web page, pretty nifty.

qui
Selenium generates functional tests rather than unit tests.Functional testing accesses the application as a user would. Unit tests access it under the hood.
Keith
A: 

Parasoft .TEST has a functionality of tests generation. It uses NUnit framework for tests description and assertions evaluation.

It is possible to prepare a regression tests suite by automated generating scenarios (constructing inputs and calling tested method) and creating assertions which are based on the current code base behavior. Later, after code base under tests evolves, assertions indicates regressions or can be easily recorded again.

zuraff