Unit Testing Level II

Slightly more advanced unit testing commands and techniques.

You can make common setup code run with @Before. Use it to give instance variables their initial values for each test. This method runs once before each test, so it will reset the variables to the values you want them to have at the start.

Common setup for all tests

@Before: Method runs before every test. Used to set up instance variables containing objects to be tested.

    private int maxNum;
    @Before
    public void set_max() {
        maxNum = 4;
    }
    @Test
    public void test_max() {
        assertEquals(maxNum,4);
    }

Many tests with the same setup

I use parameterized tests. They may be to complex for beginners, but see my HospitalTest code on GitHub or the raw file.

Last modified August 18, 2023: 2022-2023 End State (7352e87)