Before runs before the suite, BeforeEach runs before each test (if memory serves). The big feature was dynamic tests, we managed to refactor most of our tests to a single data file and a factory which generates all the tests.
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() {}
}
28
u/cypher0six Sep 10 '17 edited Sep 10 '17
Is there a list of major changes from 4 to 5 somewhere?
Edit: Found a few high level comparisons:
https://howtodoinjava.com/junit-5/junit-5-vs-junit-4/
https://howtoprogram.xyz/2016/08/10/junit-5-vs-junit-4/
https://www.ibm.com/developerworks/library/j-introducing-junit5-part1-jupiter-api/index.html