We now have unit tests for a few classes in the trunk.
This means that you can run “make test” and the test will be run. At
present, all of the tests pass. If you change something and some test
fails, then something is wrong—either your new code or the test is
broken, and you should determine which one it is. All of the tests live
under the test directory, in a structure which parallels the structure
under the src directory. A class containing tests for VASSAL.tools.Foo
will be called FooTest and be found under test/VASSAL/tools. All of the
packages under test/ are the same as those under src/. This makes
writing tests easier, since then the tests are members of the packages
where the classes they test live, but the test classes don’t clutter up
our source tree.
The unit testing framework I chose is JUnit:
It’s a well-established framework, and is easy to use. It didn’t take me
long to be able to write tests after reading their docs.
My goal with all of this is to encourage us to write tests for new code
which is testable. Doing so should help us avoid introducing new bugs.
Two notes for Eclipse users:
As of trunk@6095, you will need to add lib-nondist to your classpath.
The two JARs which are not distributed as part of releases, JUnit and
AppleJavaExtensions.jar, live there now. Moving them there simplified the
release build logic significantly, and now we have a dedicated location
for such JARs.
I’d like to be able to tell you how to run the tests from within
Eclipse. I haven’t had a chance to look into that yet. What I know right
now is that there’s a JUnit plugin for Eclipse. I would be grateful to
anyone who looks into this and can tell us how to run our test in Eclipse.