/---------------------------------------------------\ | Installing and Running a JUnit Test -- A Tutorial | | (C)2002-2003 Adam Monsen | \---------------------------------------------------/ Effective testing is almost synonymous with effective programming. Java has available an excellent testing suite called JUnit. This guide will attempt to get you up and running with JUnit in the shortest amount of time possible. I'm assuming that you have Java installed and working and you have access to a command line. --1-- INSTALL JUnit JUnit is available at http://junit.sourceforge.net. Pay special attention to this warning: "...don't install the junit.jar into the extension directory of your JDK installation...". I don't know why, but if you do this JUnit won't work as expected. How do you know JUnit works? The following command will spit out compilable Java source code: javap junit.framework.Test and this should work while you're in the directory where JUnit was unzipped: java junit.textui.TestRunner junit.samples.AllTests --2-- COMPILE SimpleTest.java Type this code in your favorite text editor and save as SimpleTest.java: import junit.framework.TestCase; public class SimpleTest extends TestCase { public SimpleTest (String name) { super(name); } public void testTest() { assertTrue(true); } } --3-- RUN SimpleTest If compilation succeeded, run this from the command line: java junit.textui.TestRunner SimpleTest And you should see output similar to the following: . Time: 0.006 OK (1 tests) Done. -Adam /----------------------------------------\ | v0.02 [ Sat Feb 22 06:34:23 PST 2003 ] | | -fixed typo in class name | | v0.01 [ Mon May 6 01:50:42 PDT 2002 ] | | -initial revision | \----------------------------------------/