22

I would like to know about good tools to automatically generate JUnit4 tests. By automatic generation, I mean that if I write a .java file, then a test file for the same should be created with method placeholders and setup/teardown in place (like the auto-generate constructors feature of eclipse)

I found some but I haven't tried them all and frankly I am overwhelmed by the plethora of choices. I was wondering if someone has tried some/all of them and has any recommendations from these or any other.

koppor
  • 19,079
  • 15
  • 119
  • 161
FirstName LastName
  • 1,891
  • 5
  • 23
  • 37

5 Answers5

6

I use the Eclipse plugin MoreUnit. It can generate TestClasses and test-methods. It also shows which methods have test methods ...

Together with TestNG(JUnit is also good) and EclEmma junit testing is quite easy to handle and keep track on the code coverage

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
  • 2
    MoreUnit is a promising tool. However, here I still have to generate tests manually by clicking on each method stub. I was wondering if there is a batch processor for what MoreUnit is doing. So that I can write all the code I want, then batch process it to generate test stubs and then fill out the tests later. – FirstName LastName Jan 03 '13 at 18:53
  • Actually I already have some code without much test code in place. So instead of clicking each method, I was looking for a batch processor. – FirstName LastName Jan 03 '13 at 21:41
4

Some suggestions: Randoop, AgitarOne, and EvoSuit for Java.

user3601784
  • 377
  • 1
  • 9
4

The Squaretest plugin for IntelliJ IDEA works well. It can auto-generate test-classes with a lot of the required boilerplate code. It supports creating tests in either Java or Groovy with the JUnit4, JUnit5, AndroidJUnit4 or Robolectric3 test frameworks.

Disclaimer: I created the Squaretest plugin.

Nate
  • 41
  • 2
3

CodePro Analytix Plugin for Eclipse is also good. Exiting thing for me is it generates multipe testcases covering all the execution paths of a method, analyses dead code and dependencies and has lot of other features. Check out the User Guide here

2

My favorite is JUnit-Tools to generate JUnit Tests and more. It's a eclipse plug-in and up to date. Further there are many possibilities to configure and to adapt.

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71
Michael
  • 21
  • 1