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.
@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);
}
I use parameterized tests. They may be to complex for beginners, but see my HospitalTest code on GitHub or the raw file.