JMUT: Java Methodical Unit Test

JMUT is a simple, lightweight, Java unit test harness. While JUnit is very nice, I wanted something that would test all the methods in a class, including the private ones. JMUT does this and more, using reflection.

For each method ("methodname") in a class, JMUT looks for a unit test method named "JMUTmethodname" that takes no parameters and returns a boolean as to whether the test passed or failed. JMUT also looks for two methods ("JMUTsetup" and "JMUTteardown") that create and initialize an instance of the class, and tear that instance back down, if necessary.

Here's a simple class that has some JMUT unit tests:

public class Junk
{
    private boolean JMUTsetup () { return (true); }
    private boolean JMUTteardown () { return (true); }

    private void uncovered () { System.out.println ("uncovered"); }
    private boolean JMUTsuperfluous () { return (true); }

    private void foo () { System.out.println ("foo"); }
    private boolean JMUTfoo () { return (true); }

    private void bar () { System.out.println ("bar"); }
    private boolean JMUTbar () { return (false); }

    private void baz () { System.out.println ("baz"); }
    private boolean JMUTbaz (int i) { return (true); }

    private void blurf () { System.out.println ("blurf"); }
    private int JMUTblurf () { return (1); }
}
Running "javac Junk.java" then "java -jar JMUT-0.1.jar Junk" produces:
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: Running: private boolean Junk.JMUTsetup()...
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: private boolean Junk.JMUTsetup() passed
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: Running: private boolean Junk.JMUTsuperfluous()...
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: private boolean Junk.JMUTsuperfluous() passed
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: Running: private boolean Junk.JMUTfoo()...
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: private boolean Junk.JMUTfoo() passed
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: Running: private boolean Junk.JMUTbar()...
Nov 9, 2005 2:35:12 PM JMUT runOne
WARNING: private boolean Junk.JMUTbar() failed
Nov 9, 2005 2:35:12 PM JMUT runOne
WARNING: Parameters not allowed for JMUTbaz, skipping
Nov 9, 2005 2:35:12 PM JMUT runOne
WARNING: Return type for JMUTblurf not correct, skipping
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: Running: private boolean Junk.JMUTteardown()...
Nov 9, 2005 2:35:12 PM JMUT runOne
INFO: private boolean Junk.JMUTteardown() passed

One can tune the messages produced by setting the logging level; "warning" is typically appropriate.

One can also call JMUT inside a program. for the above example, doing "new JMUT (new Junk()).test ();" somewhere in Junk.java does the same thing as calling JMUT externally.

Also included is a logger that automatically puts in the correct class and method names, and a handler that prints the line numbers where a logger method is called from.

JMUT can be downloaded from http://sourceforge.net/projects/jmut/.