JUnitFactory is a free experimental project from AgitarLabs. You send it Java code and it sends back JUnit characterization tests for your code.
We have made our technology freely available to academic institutions and test researchers, but some of them don’t have the spare computing or IT resources to set-up a test server, so we thought it would be a fun experiment to set-up a dozen CPUs and have students and researchers use the test generator over the web. As the experiment progresses, we plan to make APIs available so that researchers and anyone interested in automated test generation can experiment with their own characterization test generation algorithms and strategies.Before anyone starts complaining about the evil of automated test generation, let me restate that JUnitFactory can only generate characterization tests; and let me clarify what is meant by characterization tests for those that may not be familiar with the term or concept.
In "Working With Legacy Code", Michael Feathers defines characterization tests as tests that characterize and record what the code actually does – not what it’s *supposed* to do. They exercise the code with a range of inputs, and record return values, object state, etc., for each set of inputs.
Characterization tests are useful for working with legacy code which is defined, again by Michael Feathers, as any code without tests.
CTs can come in handy as change detectors when there is a large body of code with little or no tests and provide a safety net when you need to make some changes to it. If the same set of inputs results in different behavior between the original and the revised version of the code, some assertions in the characterization tests will fail. Some of those failures may point to unexpected and/or unwanted changes in behavior that you might want to know about and address.
Colloquially, and in the simplest possible terms, characterization tests will tell you things like the following:
In the original version of the code, ‘Util.foobar("abc", 123)’ returned ’42’. After you made the change, it returns ’43’.
The test has no idea whether the right return value is ’42’ or ’43’, but it lets you know that it has changed and you, the developer, has to decide which one is right and what to do about it. Sorry, no free lunch.
By now it should be amply clear that automatically generated characterization tests are NOT a replacement for TDD or Unit tests lovingly crafted by developers. But, especially with some user input in the selection of test data and test assertions (which is possible with JUnitFactory), they can give developers a valuable jump-start in working with legacy code and complement their manual testing efforts.
Unfortunately, for the time being, we only have a client plug-in for Eclipse. If enough people find the JUnitFactory useful, we plan to add support for other IDEs. As a matter of fact, if you want to help with that let us know – but keep in mind that JUnitFactory is designed to be a free service so all clients will have to be freely available or, better, open-source.
If you don’t use Eclipse, there’s a "toy" web-based demo of the CT generation also – but it only works on one class with no dependencies.
Anyway, if you have any interest in JUnit generation, go to the website, request an invitation and give it a try.
Remember, it’s still experimental and mostly for fun so don’t expect too much or bang on it too hard.
Agitar Software Laboratories