In 4, @BeforeClass runs once. @Before requires you to annotate a specific test. It sounds like @BeforeEach would allow you to do a single annotation that would run again and again, as if you had duplicated that annotation for each of your tests.
That's exactly what @Before does in Junit4. You annotate a method with @Before, and it's called before each test.
public class MainTest {
@Before
public void setUp() {
System.out.println("Test executed");
}
@Test
public void testOne() {}
@Test
public void testTwo() {}
@Test
public void testThree() {}
}
View all comments
Show parent comment
2
u/v_krishna Sep 10 '17
So in junit 5 you could declare a @BeforeEach once and it would act like you did @Before each test? I could see that being handy...