fork download
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;

class SimpleTest {

    @Test
    public void testAddition() {
        int result = 2 + 2;
        assertEquals(4, result);
    }

    @Test
    public void testSubtraction() {
        int result = 5 - 3;
        assertEquals(2, result);
    }

    @Test
    public void testMultiplication() {
        int result = 4 * 3;
        assertEquals(12, result);
    }

    @Test
    public void testDivision() {
        double result = 10 / 2;
        assertEquals(5.0, result, 0.0001); // third parameter is the delta for floating-point comparison
    }
}

class Main {
    public static void main(String[] args) {
        Result result = JUnitCore.runClasses(SimpleTest.class);
        for (Failure failure : result.getFailures()) {
            System.out.println(failure.toString());
        }
        if (result.wasSuccessful()) {
            System.out.println("All tests passed!");
        }
    }
}
Success #stdin #stdout 0.17s 59708KB
stdin
Standard input is empty
stdout
initializationError(SimpleTest): Test class should have exactly one public constructor
initializationError(SimpleTest): Class SimpleTest should be public
initializationError(SimpleTest): Class SimpleTest should be public
initializationError(SimpleTest): Class SimpleTest should be public
initializationError(SimpleTest): Class SimpleTest should be public