问题
Are there any libraries for Java that can generate unit tests or unit test skeletons for existing code? I'm looking for something similar to pythoscope. Ideally it would generate code that follows JUnit4 or TestNG conventions.
It looks like Agitar does something like this, but I'm looking for something free.
回答1:
Most IDEs will generate test method stubs for any class. I know Eclipse will.
New->JUnit Class then you tell it which class you're testing and what methods you want to test.
回答2:
My plugin creates unit tests, it does both JUnit or TestNG tests. Hope you like it. http://fast-code.sourceforge.net/
回答3:
Agitar had a free service that allowed you to do this (you had to be prepared to let it send your code to their servers).
If you were using scala, there is "scala check" - but I am not sure how well it works with java source (even though its all byte code).
回答4:
I've been trying to get TestGen4j running but it looks like it hasn't been maintained :( Perhaps you give that a try?
回答5:
from the makers of the google : ( https://developers.google.com/java-dev-tools/codepro/doc/features/junit/test_case_generation)
CodePro Analytix
The CodePro JUnit Test Case Generation facility allows you to automate the creation of comprehensive JUnit regression test cases. Given an input class, the tool creates a corresponding test class complete with multiple test methods for each input class method. The tool analyzes each method and input argument with the goal of generating test cases that exercise each line of code
来源:https://stackoverflow.com/questions/125100/free-open-source-test-generator-for-java