What is the purpose of @Before and @After annotations in JUnit 4?
These are the annotations present in JUnit 4
. Methods annotated with @Before
will be called and run before the execution of each test case. Methods annotated with @Afte
r will be called and executed after the execution of each test case. If we have 5 test cases in a JUnit class, then the methods annotated with these two would be run 5 times. In JUnit 5
, the annotations @Before
and @After
are renamed to @BeforeEach
and @AfterEach
for making it more readable.