Brendan Tompkins [MVP]

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Automatic NUnit Unit Test Generation?

The other day, I emailed Darrell about SkeletoNUnit.

>Know anything about this?
>
>http://sourceforge.net/projects/skeletonunit/
>
>Looks interesting, I remember you were talking about NUnit addins, and
>got me thinking of an automatic unit-test generator.  Should be fairly
>easy to make one, so I thought for sure there's one out there.
>
>I know it's backwards to generate unit tests, but I can see the
>advantages, especially with legacy code.

Anyhow, he didn't know of anything else off-hand, and SkeletoNUnit seems, like it's name suggests, to be a dead project...  So, I'm asking if anyone knows of anything else out there that will do this?  Basically, I'm looking for something that will automate the generation of NUnit unit tests. 

I've tried .TEST from Parasoft, (which does generate NUnit tests) but I couldn't get it to work fully.  It would choke on big assemblies, and I couldn't figure a way to generate tests for one class at a time.  I also can't justify the price tag, when VS2005 may do much of this stuff and make .TEST obsolete..

-Brendan


Posted 09-17-2004 10:48 AM by Brendan Tompkins

[Advertisement]

Comments

Michael Russell wrote Defeat the purpose?
on 09-17-2004 7:09 AM
Doesn't automatic generation of test cases defeat the purpose of testing?

The best part about TDD is that you really have to think out how to test your components. You need to think of valid inputs, invalid inputs, etc. and test for them.

What's even more important is creating a unit test to test your bug fixes. Take the case which triggered the bug and create a test case for it.

Parasoft's unit testing software is good at coming up with generic test cases, but is abhorrent at coming up with intelligent test cases that are truly useful.
Rob Gibbens wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 7:13 AM
Well, in the simple cases, it could be very useful. Say you have an object with some properties on it. Say one of these properties (FirstName) is a string. An Automatch Test Generator could see that property, see that it's a string, and pop up a box asking 1. Maximum length for this field 2. Is it allowed to contain non-alpha characters, etc. Common things for strings. Another property may be a collection. It should be able to automatically test adding a new object and testing that the object is in the collection. It's obviously not going to be able to generate every test case, but it should be able to generate the simple, common cases, leaving you more time to think about the not-so common cases.
Brendan Tompkins wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 7:18 AM
I agree with both of these comments so far. New development - write unit tests first. But for maintaining/debugging old code, or to write a test for that code you had to churn out (or for the time you cheated on your test-first diet) it'd be really nice to have some tests generated for you.
Rev wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 7:57 AM
Yes, I'm about to do some major refactoring and wholesale rewriting of a project I did before I found the joys of NUnit. I'd rather generate NUnit test that represent the state my project is in now so I can use it to make my changes.

I'll have to flag this conversation in case anyone comes up with a solution.

Until then... I've got a lot of tests to write.

Rev
Darrell wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 8:49 AM
An earlier version of the NUnitAddin to Visual Studio could do this for a class, but not, as far as I know, with a whole assembly. I'm sure it could be done via Reflection.
Darrell wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 8:52 AM
Brendan Tompkins wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 9:20 AM
Darrell,

I had found that too, but I can't make any sense of the posts. Can you? Is there a Reflector plugin?
Brendan Tompkins wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 9:45 AM
Okay.. I got something to work:

First Download Reflector:

Then Download "Reflector.Graph.Addins" :

http://www.dotnetwiki.org/Default.aspx?tabid=52

Run Reflector, select "AddIns..." and add the dlls from the Reflector.Graph.Addins.

Then Load Your dll in Reflector, right click on the class, choose "Code Generators", then Select "Unit Tests" from the ddl, set your namespace in the properties pane, right click below the properties pane, then click "Generate" cross your fingers, sacrafice a small goat, and hopefully you'll get a test case out of it.

I'm not complaining, but there has to be a better way.

-Brendan
Brendan Tompkins wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 9:46 AM
Oops, reflector is here: http://www.aisto.com/roeder/dotnet/
Rev wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 10:24 AM
I'm getting an exception:

System.ArgumentOutOfRangeException

when I try and generate the test. Where is the output? Or would that pop up if I didn't get the exception?


Also... only 4 of the .dlls in the Add-in loaded for me... the rest failed with a message that they did not contain packages.

Rev
Brendan Tompkins wrote re: Automatic NUnit Unit Test Generation?
on 09-17-2004 2:26 PM
Hi Rev.. Yes. I got this message on some classes too. I'm not sure what the breaking point is or why that's happening.

Me too about the DLLs as well. The others I don't think apply, so I'm pretty sure its okay..

There's an output directory field in the parameters section. You can pick a directory with it, and that's where the classes go when and if they work.

I'm just playing around with it too... Let me know if you get any further.

We should probably post this stuff on Peli's Blog
Josh Pollard wrote re: Automatic NUnit Unit Test Generation?
on 09-20-2004 5:30 AM
It looks like Peli took it down:

"Reflector.Graph.Addin temporarly removed.."
Rev wrote re: Automatic NUnit Unit Test Generation?
on 09-20-2004 10:27 AM
We must've been hitting it too hard, mini-/. effect.

I got some of my smaller classes done, but the big guys bombed out. I decided to skip the autogen and do it all by hand. I guess that's the way it was meant to be done in the first place.

I picked up 'TDD in Microsoft .NET' by Newkirk and Vorontsov, as a primer for NUnit. I kind of found that it was more like a quick start pamphlet you often times get in your packaged software.

Has anyone looked at "Extreme Programming Adventures in C#" http://www.amazon.com/exec/obidos/tg/detail/-/0735619492/qid=1095715609/sr=8-1/ref=sr_8_xs_ap_i1_xgl14/104-2632373-7360715?v=glance&s=books&n=507846

Is it worth grabbing?

Rev
Jonathan de Halleux wrote re: Automatic NUnit Unit Test Generation?
on 10-03-2004 10:30 PM
Hi all,

I'm the author of the Reflector addin that "should" output "empty" unit test cases out of .NET assembly.

First thing I have to say is that: it is EXPERIMENTAL. Second, there are a lot of traps that this tool could fall in:

- The statement graph that I build is not perfect and still suffers some bug
- it does not generate "minimal" path test cases because I'm using a basic depth-first-search approach
- Reflector decompilator is not perfect and sometimes fails

Nobody should hope for miracles with automatic test generation, because it tries to solve an undecidable problem (Hamming theorem).

At last, you should definitely forward this kind of feedback to me.

Cheers,
Jonathan
Brendan Tompkins wrote re: Automatic NUnit Unit Test Generation?
on 10-04-2004 7:24 AM
Jonathan... Thanks for the post. Good job getting your PhD! Maybe this addin tries to do too much? Perhaps something more useful would be just generating tests that are empty, with System.NotImplementedExceptions being raised.

-Brendan
Jonathan de Halleux wrote re: Automatic NUnit Unit Test Generation?
on 10-20-2004 3:01 AM
There is an option in the property grid to disable path generation and simply generate 1 test per method.
edwinyeah wrote re: Automatic NUnit Unit Test Generation?
on 07-21-2005 2:15 AM
Hi all,

I noticed SkeletonNUnit before, but unfortunately it seems to be dead? and I searched the Internet but I found nothing. so I developed one by myself, check

http://www.freewebs.com/edwinyeah/

Features
1. Supports popular languages including C#, VB.Net, JScript, Managed C++ and J#.
2. Options for generate test cases for a whole module, a whole class or a single method.
3. Options for output to files or on-screen.
4. All parameters of methods being tested are assigned with default values; also members of non-primitive type of parameters are assigned with values.
5. Options for generate a "for loop".
Terry Go wrote re: Automatic NUnit Unit Test Generation?
on 01-19-2006 9:45 AM
Hi,
I also has been thinking of this NUnit test generation tool for a long time and VS2005 team edition shipped this functionality. However, as always, it supports only their own testing framework, which is not what I want, since I invested a lot on NUnit. So, I finally created NUnitGenAddin, VS2005 add-in that you can generate NUnit tests as you code. Check that out here, http://forge.novell.com/modules/xfmod/project/?nunitgenaddin.
Mario Muja wrote re: Automatic NUnit Unit Test Generation?
on 02-18-2006 3:10 AM
Hi Terry,
you write that NUnitGenAddIn is for VS2005. However, on the download page your comment says that 0.1.0.1 is for VS2003. Should this be also usable for VS2005?

Thanks for clarification,
Mario
Mario Muja wrote re: Automatic NUnit Unit Test Generation?
on 02-18-2006 3:11 AM
Hi Terry,
you write that NUnitGenAddIn is for VS2005. However, on the download page your comment says that 0.1.0.1 is for VS2003. Should this be also usable for VS2005?

Thanks for clarification,
Mario
Terry Go wrote re: Automatic NUnit Unit Test Generation?
on 03-20-2006 12:36 PM
Sorry for the late reply.
I created two different versions of NUnitGenAddIn for both VS.NET and VS2005. Version 0.1.1 for both VSes are now available for download along with class diagram if you are interested. Enjoy~~ :)
Andrzej Stencel wrote re: Automatic NUnit Unit Test Generation?
on 03-28-2006 8:54 AM
Hi Terry

Your solution works for me, I use VS2005. It's simple and works fine.

One thing I wanted to change was for the test methods to have the word "Test" postfixed rather then prefixed. However, I have achieved this with a simple 'Find and Replace' using regular expressions:
Find: "public void Test{[^(]+}\("
Replace with: "public void \1Test(".

Andrzej

Thanks again, great job!
san wrote re: Automatic NUnit Unit Test Generation?
on 05-05-2006 4:13 PM
hi terry
as i was googling for the codegenerator i came across this forum. I went through ur link.I downloaded testgenerator for vs 2005 but i could not generate tests i dontknow wht the problem is are there installation directions for this tool bec i dint find any on the site.If u have can u post it.
Igor Vachshuk wrote re: Automatic NUnit Unit Test Generation?
on 05-09-2006 1:13 PM
No installation required. Just run .reg file
Terry Go wrote re: Automatic NUnit Unit Test Generation?
on 08-28-2006 2:28 PM

san,

I just posted a lame manual on the project page (http://developer.novell.com/wiki/index.php/Special:Downloads/nunitgenaddin/NUnitGenAddIn-Manual-v0.1.1.doc).

Hope this answers your question.

Thanks for you interests :)

Nathan wrote re: Automatic NUnit Unit Test Generation?
on 08-31-2006 4:26 PM

I am having problems with the add in for vs2005.  It is giving me a null reference exception when I select generate tests.  Any idea what might be going on?

Anonymous wrote re: Automatic NUnit Unit Test Generation?
on 05-07-2007 5:33 AM

Hi,

I am getting an exception while Visual Studio 2003 and 2005 is loading the Addin. Can you please help me out.

Thanks in advance

Tim Wingfield wrote re: Automatic NUnit Unit Test Generation?
on 09-16-2007 12:11 AM

I just saw another NUnit Test Generator.  The price is really reasonable.  It works too.  

www.kellermansoftware.com/p-30-nunit-test-generator.aspx

automatic Unit test generation « Amr’s Weblog wrote automatic Unit test generation « Amr’s Weblog
on 07-02-2008 2:12 PM

Pingback from  automatic Unit test generation « Amr’s Weblog

Rejkpolg wrote re: Automatic NUnit Unit Test Generation?
on 08-18-2008 7:41 PM

For NUnitGenAddIn one cause of null reference is lack of namespace in classes, add one or:

replace any occurance of:

string targetNamespace = (targetClass.Parent as CodeNamespace).FullName;

with:

string targetNamespace;

if ((targetClass.Parent as CodeNamespace) == null) targetNamespace = "";

else { targetNamespace = (targetClass.Parent as CodeNamespace).FullName; }

And my short review cause i'm retyping this: I think i'd prefer generation of just empty stubs to all the stuff he tries to generate.  The add-on works well tho after that namespace problem.

Clint wrote re: Automatic NUnit Unit Test Generation?
on 08-18-2008 10:38 PM

Have you looked at Doubler by Jay Flowers?

jayflowers.com/.../index.php

Add a Comment

(required)  
(optional)
(required)  
Remember Me?