How to use JUnit

There are two versions of JUnit currently in use: Version 3 and 4.

JUnit can only test methods, not general input/output of a program. For general input/output one needs blackbox tests or one needs to write a method that returns the output before it is actually printed. For example, a 'HelloWorld' program could be written like this:

public class hello {
    public String greet() {
        return "Hello, world";
    public static void main(String[] args) {
        hello h = new hello();

and then be tested with JUnit 3 like this:

import junit.framework.TestCase;
public class TestHello extends TestCase {
    public void testHello()
        hello h = new hello();
        assertEquals(h.greet(), "Hello, world");

Apart from assertEquals, other tests can be used (delta sets the precision for float and double):

assertEquals([message,] expected, actual)
assertEquals([message,] expected, actual, delta)
assertFalse([message,] condition)
assertNotNull([message,] object)
assertNotSame([message,] expected, actual)
assertNull([message,] object)
assertSame([message,] expected, actual)
assertTrue([message,] condition)
failNotEquals(message, expected, actual)
failNotSame(message, expected, actual)

The test should be uploaded as a .java file using the "Create File Checker" and be used with the JUnit Checker. The class file of the test will be generated by the Praktomat. Note: in the Create File Checker the filename should be the java file of the test, whereas in the JUnit Checker the class filename should be provided. In case of JUnit 4 the class should be provided without the extension "class". The tests should not be compiled as part of a package. Further documentation can be found on the JUnit 3 and JUnit 4 websites.