- Create a main class
import junit.textui.TestRunner;
public class TestBootstrap
{
public static void main(String[] args)
{
TestSuite testSuite=new TestSuite();
testSuite.addTestSuite(TestClass.class);
TestRunner.run(testSuite);
}
}
2. Create an ant build file
<project>
<target name="eclipse-test-runner">
<java classname="TestBootstrap" classpath="bin:libs/junit.jar"> <java> </target>
</project>
3. Create a Builder in eclipse
Open project properties: Right click project -> Propertie. Create new ant builder step after the Java Builder in eclipse: Builders -> new -> Ant Builder. Give your builder a nice name.
Main: Select the build file and the base directory
Targets: Select your ANT target for: “After Clean”, “Manual Build”, and “Auto Build” (most important) Build Options: Check “Specify working set” and select all of your source folders.
And thats all, now every time you save a file, eclipse will run the ant target specified in your build file, which incidentally calls your TestBootstrap's main and invoked all the tests.