The following tutorial shows how to add a 'Run JUnit' tool to TextPad that will execute JUnit tests.
First, download junit.jar from http://www.junit.org. Save it in a reasonable folder on your computer, such as in your JDK's folder, or something like C:\Program Files\JUnit. (That's the location I'll use in the rest of the steps. If you use something different, substitute that.)
click Configure -> Preferences...
click Tools -> Add -> Program...
Browse to the path of javaw.exe for your installation of JDK. The default folder for this is C:\j2sdk1.4.xxx\bin. Select javaw and choose OK.
You should now see a tool in the list named 'javaw'. You can click it a few times to rename it to something more meaningful, like 'Run JUnit'.
Click Apply. Now the new tool should appear on the left sidebar underneath Tools if you expand Tools with the + icon. Expand Tools and select your new tool.
Make the following changes to the parameters for your tool:
Parameters: -cp ".;C:\Program Files\JUnit\junit.jar" junit.swingui.TestRunner $BaseName Initial folder: $FileDir
Notice that the part after the cp starts with a dot and a semicolon, and is surrounded by quote marks. Also select the 'Compile Java' tool and make the following changes to its parameters:
Parameters: -classpath ".;C:\Program Files\JUnit\junit.jar" -source 1.4 $File
Click OK.
To test your JUnit tool, open a .java file that represents a JUnit test case. (Here is an example file to test with: DateTester.java)
Compile it with the normal 'Compile Java' tool. If you did everything right so far, it should compile successfully. Then execute your 'Run JUnit' tool.
You should see the JUnit UI appear and run your test.
If you get errors like these:
C:\Documents and Settings\stepp\Desktop\temp\DateTester.java:1: package junit.framework does not exist
import junit.framework.TestCase;
^
C:\Documents and Settings\stepp\Desktop\temp\DateTester.java:3: cannot resolve symbol
symbol : class TestCase
location: class DateTester
public class DateTester extends TestCase {
Then it means that TextPad can't see your junit.jar. Double-check the path names and parameters and try again.
If you'd like to be able to use JUnit globally on your computer and not just from within TextPad, add JUnit to your CLASSPATH. This will let Java programs see JUnit when they are compiling and running. To do this, click Start -> Settings -> Control Panel, then open the System control panel. (Alternatively, press Windows Key + Pause/Break to shortcut to this panel.) Click the Advanced tab, then click Environment Variables.
Under System Variables, see if there is an entry named CLASSPATH. If so, select it and choose Edit. If not, click New and type CLASSPATH for Variable name. Either way, for Variable value, add the following at the end:
.;C:\Program Files\JUnit\junit.jar