MalletMain Page | About | Help | FAQ | Special pages | Log in
Advanced Machine Learning for Language
Printable version | Disclaimers

Guidelines for writing unit tests

From Mallet

When you add code to base/, please write unit tests if you can. The idea behind a unit test is (a) it usually tests a small part of your code, perhaps even a single function, and (b) the test needs to be completely automated, i.e., it can tell on its own whether it succeeded, without human intervention. We use JUnit (http://www.junit.org) for writing tests, which is fairly simple to use.

Short version: Most of the time, you can create unit tests simply by copying the class base/util/TestCaseTemplate.

Long version: We have a test harness that runs all our test cases automatically. In order to play nicely with this test harness, your test cases need to follow some guidelines, listed below. They seem like a lot, but once you know them, they're really quite easy.

  src/edu/umass/cs/mallet/base/util/tests/TestMyNewClass.java

then your data file can be committed to cvs at

  test/edu/umass/cs/mallet/base/util/my-data-file.txt
       src/edu/umass/cs/mallet/base/util/

then most of the time put the test case in

       src/edu/umass/cs/mallet/base/util/tests/

Sometimes this isn't feasbile, in particular when your test case needs package-local access to the class you're testing. You could put the test case in base/util, but this could clutter up the higher-level directory. Instead, you may place your test case in the test/ hierarchy as well, for example

       test/edu/umass/cs/mallet/base/util/

Retrieved from "http://mallet.cs.umass.edu/index.php/Guidelines_for_writing_unit_tests"

This page has been accessed 4319 times. This page was last modified 09:26, 23 Jun 2006.


Find
Navigation
Main Page
Community portal
Recent changes
Random page
Help
Donations
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Create an account or log in
Special pages
New pages
Image list
Statistics
Bug reports
More...