views:

971

answers:

4

Hi,

Has anybody tried any Unit Test generators for .Net?

I assume although it won't be any substitute for any good unit test written by a person who has written the functionality, but I think it will take away some of work and be a starting point on which we can better the unit tests.

Thanks.

+6  A: 

Unit test generation is the wrong way to perform unit testing. The proper way to do unit testing is to create test cases before you write functional code, then develop your code until the tests validate, this is know as TDD (Test Driven Development).

One of the key reasons unit test generation is a bad idea is because if there are any bugs in your existing code, the tests will be generated against those bugs, therefore if you fix them in the future, the bad tests will fail and you'll assume something is broken, when it's actually been fixed.

But since the code is written, it's now water under the bridge. And possible buggy unit tests are better than no unit tests at all. I've always preferred NUnit and there's a NUnit compatible test generator here (very affordable).

TravisO
Yeah it's the wrong way to do TDD, but if you are working with Legacy code it's a good foundation no?
Webjedi
@Webjedi. I don't think so. Writing the tests by hand will help you understand what the code is supposed to be doing. Running a test generator -- with the questionably readable code it would produce -- doesn't help with that.
tvanfosson
Exactly. How would a tool know what the behavior of your application is supposed to be? If you've got no tests, you're better off writing functional tests for the UI using WatiN or Selenium, etc
bryanbcook
+3  A: 

Have you considered Pex? It's from Microsoft Research.

Pex automatically produces a small test suite with high code coverage for a .NET program. To this end, Pex performs a systematic program analysis (using dynamic symbolic execution, similar to path-bounded model-checking) to determine test inputs for Parameterized Unit Tests. Pex learns the program behavior by monitoring execution traces. Pex uses a constraint solver to produce new test inputs which exercise different program behavior.

Pascal Paradis
Pex is worth looking at. I've found it useful for the growing list of extension methods we write, which up to now have gone untested.
Frep D-Oronge
+1  A: 

By writing your tests after you write the code, you pretty much end up testing your implementation rather than testing the intentions.

If you write your test before the code, you'll also benefit from acting as a user of your code. In my experience that offers many useful hints for designing the interface of the types in question.

Brian Rasmussen
+2  A: 

Years ago I modified Haskell's QuickCheck to allow for purely functional Test Driven Development with generative tests. My solution was to save the PRNG seed for that generated a failing test case, and run future tests with that same seed.

I recently got a .NET job, and Google found that MbUnit did have support for generative tests in 2004. I also found the more recent Gallio, but I had some sort of trouble using it, I don't remember exactly what.

So, TDD and generative testing are not mutually exclusive, Gallio is the only recent .NET option I've seen, and I don't remember why I'm not using it now.

shapr