JSwat Unit Testing

Unit Tests Defined

Unit tests are basically bits of code that exercise functions within a project. If each test cases passes, there is a good chance the system is in proper working order. That is by no means guaranteed, and verifying this falls into the realm of integration testing, and which is performed manually.

The JSwat unit tests are written to use the JUnit framework. This provides the classes for automating the execution of the tests, making it very easy to run the tests over and over again.

Running the Tests

To run the test suite you will need the latest version of the Apache Ant tool. While the process could be accomplished without Ant, it would take longer to explain than it does to install this extraordinarily useful tool. After installing Ant, you will need to copy the junit.jar file (which you get from the JUnit website) to the lib directory in the Ant installation directory. In this way, Ant can easily run JUnit tests using the junit tag.

With Ant installed and JSwat compiled, running the unit tests is a simple process. Open a command shell window and change to the top-level JSwat directory (where the README.html file is found). From there, invoke Ant with the "test" target, like so: ant test

Soon after invoking this command you will see the JSwat window appear and start reacting to the test code. Wait until the window closes and Ant has finished running the tests.

It is important that the tests are performed in the top-level directory. Otherwise many of the tests will fail to work correctly. In particular, the classpath and sourcepath are set using relative paths, and the Java parser test uses a relative file path to load one of the test files.

Writing New Tests

The best way to learn about writing test cases is to look at the existing test code. It is generally very simple and straight-forward code. Bear in mind that any new test cases must be added to the appropriate collection (e.g. AllTests, ActiveTests, etc.) within the particular Java package. Otherwise they will not be run when the test suite is executed.