In my following example I am unsure if I should use BeforeEach
or BeforeAll
- Note the class under test Calculator
does not change state etc between tests so I assumed making it static
and using BeforeEach
is more efficient?
public class CalculatorShould {
private static Calculator calculator;
@BeforeAll
static void setUp() {
calculator= new Calculator();
}
@Test
void calculatePriceForTwo() {
// act
Double price = calculator.calculatePrice(2);
// assert
assertEquals(10, price);
}
@Test
void calculatePriceForFour() {
// act
Double price = calculator.calculatePrice(4);
// assert
assertEquals(20, price);
}
}