JUnit

From Dogtag
Jump to: navigation, search

Overview

PKI uses JUnit framework to write unit tests.

Writing tests

In JUnit 4 it's no longer necessary to extend from TestCase class. The test methods can be marked using @Test annotation.

public class PrintableConverterTest {

    @Before
    public void setUp() { ... }

    @Test
    public void test1() throws Exception { ... }

    @Test
    public void test2() throws Exception { ... }

    @Test
    public void test3() throws Exception { ... }

    @After
    public void tearDown() { ... }
}

Running tests

JUnit provides a command-line to run the tests:

java -cp <classpath> org.junit.runner.JUnitCore [Test classes...]

However, the standard tool does not generate test reports. A new tool has been provided to run the tests and generate reports:

java -cp <classpath> -Djunit.reports.dir=<report dir> com.netscape.test.TestRunner [Test classes...]

See also Running Unit Tests in CMake.

References