Testar is a tool designed to reduce the time spent running Java unit tests.
Additionally, Testar allows you to find out which methods a given test covers, and vice versa.
How it works:
The first time Testar is invoked, it runs all tests in JUnit test suite(s) given to it, and for each testXXX() method records code coverage information: what application methods are exercised (covered) by this test. This information, along with checksums for application/test classes and methods is saved into the Test Database (TDB).
On subsequent invocations, Testar finds out (using the saved checksums) what classes and methods you have changed. Based on this data, it selects for running only those tests that exercise the updated code. It is assumed that other tests, that passed before, will pass again, since nothing has changed in the code that they exercise. Of course, if any test didn't pass before, or if a test is new, Testar will run it unconditionally.
The above algorithm implies that all the (changeable) input for the tests is in the test code. If your tests depend on input from other sources, e.g. resource files, you should give Testar names of these files. When such a file changes, Testar will rerun all or selected tests, depending on additional options that you may specify.
How much time does it save?
Time savings may vary depending, equally importantly, on:
The amount of changes to the code
How "popular" is the piece of code you have changed
How much code each test covers
How many tests there are in your suite(s)
Generally, the smaller your changes are (or the more frequently you run Testar), and the more tests you have, the bigger are the relative savings. On the other hand, if there are some method(s) in your application that are exercised by all or most of the tests, any change to such a method will cause all these tests to rerun. That said, in practice for large applications the author has observed an average 60-70 per cent reduction in time to run tests.
How do I use it?
To use Testar, you will have to add the following options to the command line that invokes your test suite:
-javaagent:< Path to Testar.jar >=< Testar options >
For example, if normally you invoke your test suite as
java -classpath junit.jar:MyApp.jar junit.textui.TestRunner myapp.MyAppTests
you should modify the above line, at a minimum, as follows:
-classpath junit.jar:MyApp.jar junit.textui.TestRunner myapp.MyAppTests
where the tdb option specifies the name of the Testar DB file, in which the tool will keep the information about your tests' code coverage.
Below is the list of all Testar options (to pass multiple options to the tool, specify them as option1=value1,option2=value2,...).
· Java 1.5