Automatic generation of unit tests for Java? [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question 开发者_如何转开发Any tool for automatically generating unit tests for Java code?
UPDATE: Primary intended use is to quickly generate unit tests for legacy code that is going to be refactored. No need to automatically keep the tests in sync with the code after automatic generation.
Almost same question was asked here, but the answer was for .NET instead of Java (Pex was the accepted answer):
Automatic generation of Unit test cases for .NET and Java
Commercial tools:
- AgitarOne seems to be the biggest player in the field. There exists also 30-day trial and free web interface called JUnit Factory. There's an independent review of the tool usage in here, for example. Test generation of AgitarOne heavily focuses on the regression tests.
- Jtest is another big player, which has been around since 1998. A free trial exists. Both AgitarOne and Jtest have been awarded multiple times, and they are both Eclipse-based IDE:s.
- SilverMark Test Mentor, Java Edition is a commercial product that apparently can also create tests based on java code. This product I have no experience with.
Free tools:
- CodePlex AnalytiX used to be a commercial tool (it was the first commercial plugin for Eclipse back in 2001), but since Google bought the company developing it, the product has been released as free. It's a full IDE based on Eclipse and a finalist of Jolt Award in test generation at 2007. The features are nice, but the tool hasn't been updated in long time, so it unfortunately doesn't work with current versions of eclipse, and seems to have problems with code requiring java >= 1.5.
- EvoSuite is a a winner of SBST (Search-Based Software Testing) '13 unit test generation competition as well as SBST '17 unit test generation competition. There exists an Eclipse plugin, web interface and command line version of the tool. There is a regression criteria documented, but apparently it doesn't work yet - the tests generated target for branch coverage, weak mutation coverage or strong mutation coverage.
- Randoop uses feedback-directed random test generation approach. The tool has been around since 2007 and has been in continuous development. Randoop can produce both regression tests and error-finding tests. It's a robust and reliable command line tool, and Eclipse plugin exists as well.
- Palus claims to use both dynamic and static analysis, and is building on top of Randoop. Its authors claim that it has been used internally at Google. My experience with this software is that at least the current version (0.2) seems to have some internal issues and it doesn't seem to scale up well.
- Daikon, Eclat, Javalanche, Java PathFinder, JCrasher, jWalk, Korat, RecGen and ReCrash are free tools that are available as well.
Note that tests generated by Jtest and AgitarOne both depend on licenced runners and they can't be run if you don't have their plugins integrated. This is not the case for free tools I've tested, which generate independent tests.
Disclaimer: I'm not affiliated with any of these tools but I have done academic research on the subject.
- CodePro Analytix has a JUnit test generation module that sounds like it will do what you want. See the User Guide.
- [CoView] was a reasonably priced product, at only $9.99 per user per year, unfortunately it doesn’t exist anymore.
- AgitarOne Automated JUnit Generation is worth investigating.
All three products have a try before you buy option, so you could use them to compare the generated code against a small subset of your application.
NetBeans does it automatically from Java source files (I guess the other IDEs too).
Maybe you could take a look into the junit plugin (link is currently down :-()?
Netbeans 8 has a built-in capability to build unit tests that are more than stubs. To use this feature:
- Open the class you want to test.
- Select
Create/Update Tests
from theTools
menu. - Select whatever features you want.
- Open the created unit test and finish the remaining parts of the test.
I think Agitar had a tool like this called AgitarOne. I think you can still get it but make sure the company is still there.
How about using Randoop https://randoop.github.io/randoop/ . This works for both Java and .NET
精彩评论