2

I am looking to automatically generate unit tests in MonoDevelop/.Net.

I've tried NUnit, but it doesn't generate the tests. In eclipse, the plug-in randoop does this, however it targets Java and JUnit.

How can I automatically generate unit tests in MonoDevelop and/or for .Net? Or perhaps there is an existing tool out there I am unaware of...

MartinStettner
  • 28,719
  • 15
  • 79
  • 106
eduardosufan
  • 1,441
  • 2
  • 23
  • 51
  • 1
    To me it's not clear how you want to "automatically" generate unit tests? It seems that randoop only generates more or less random code (i.e. method calls) and checks for some very primitive properties or `equal()`. Are you looking for a tool that does the same thing for .NET (I'm not aware of any such tool...)? In my opinion this isn't a good approach to unit testing – MartinStettner Nov 27 '12 at 20:10
  • I need to generate calls to methods of a class, with different possible values ​​and that after his execution produce a report with tests passing and failing This should be a plug-in for Monodevelop. I have a proyect of a game there – eduardosufan Nov 27 '12 at 20:24
  • Are you looking for a tool that, given a class to be tested, will generate the skeleton of a unit test for that class's public methods? – dgvid Feb 27 '13 at 23:10
  • Randoop is available as a standalone tool for Java, not just as an Eclipse plug-in. Also, a version of Randoop for .NET is available at http://randoop.codeplex.com/. However, it hasn't been recently updated. – mernst Oct 14 '14 at 07:57
  • ABB Corporation has released an updated version of the Randoop.NET tool for automatically generating unit tests, at https://github.com/abb-iss/Randoop.NET. It fixes bugs, adds new features, and adds a GUI. – mernst Jun 06 '15 at 16:01

1 Answers1

8

Calling methods with different (random) input is just one part of the process. You also need to define the correct result for each input, and I don't think a tool can do that for you.

randoop only seems to check very few very basic properties of equal, which is not of great use imo and also might lead to a false impression of correctness ("Hey look, all tests pass, my software is ok" ...)

Also just randomly generating code (and input) has the risk of undetermined test results. You might or might not get tests that really find flaws in your code.

That said, a quick googling gave the following starting points for approaches you might want to take:

  • You might be interested in using test case generators (this CodeProject article describes a very simple one). They support you in generating the "boilerplate" code and can make sure, you dont miss any classes/methods you want to test. Of course, the generated tests need to be adapted by defining proper (i.e. meaningful) input and (correct) output values. Googling for "NUnit Test generators" will give you other links, also for commercial software, which i don't want to repeat here ...
  • NUnit (and other testing frameworks) support parameterized tests: These can be used to test a whole class of input scenarios. For NUnit, i found the Random attribute which lets you generate random input (in a certain range) for your methods. Remember what I wrote above about random test inputs: the results of these tests will not be reproducable which renders them useless for automatic or regression testing.

That said, also look at this question (and certainly others on SO), which may support my argument against automatic unit test generation.

Community
  • 1
  • 1
MartinStettner
  • 28,719
  • 15
  • 79
  • 106
  • thank you for your help, I used the CodeProyect Article and wrote test cases manually – eduardosufan Nov 28 '12 at 18:47
  • Per its documentation, Randoop checks more than just properties of equals. Furthermore, it can create regression tests with rich assertions to ensure that behavior does not change from run to run, which is the real purpose of testing. Bug-finding by running a lot of executions that you don't want to turn into test cases is also useful, and Randoop can do it too, but it's not related to automatically creating test suites. – mernst Sep 29 '14 at 16:25