UnitTestBase

I’m developing an app and I know I will write a good number of test cases in JUnit. I decided to create a base class for all unit test classes. It looks like the following.

import org.junit.Test;
import java.io.IOException;

public class JenkinsServerTest extends UnitTestBase
{
    public JenkinsServerTest() throws IOException {
        super();
    }

    @Test
    public void test_ReadJenkinsBaseUrl()
    {
        assertEquals("http://jenkins.hoge.com", Settings.getProperty("JenkinsBaseUrl"));
    }
}

It basically exposes Properties (Settings) object to the child classes that extends this UnitTestBase. This way I won’t have to write the code to read the settings from the properties file. The code below shows a test class that uses the exposed Settings from the base class.

import org.junit.Test;
import java.io.IOException;

public class JenkinsServerTest extends UnitTestBase
{
    public JenkinsServerTest() throws IOException {
        super();
    }

    @Test
    public void test_ReadJenkinsBaseUrl()
    {
        assertEquals("http://jenkins.hoge.com", Settings.getProperty("JenkinsBaseUrl"));
    }
}

Author: admin

A software engineer in greater Seattle area

Leave a Reply

Your email address will not be published. Required fields are marked *