I want to convert from JUnit 4 to 5 in Eclipse Oxygen 4.7.3a. I thought adding the Jupiter library would be sufficient: libraries, build path, etc. However, @BeforeAll
, @AfterAll
, @BeforeEach
, and @AfterEach
do not get executed, but the @Test methods do--but of course they fail without the proper setup.
Interestingly, I can create a file using the new Junit 5 Jupiter wizard, and that test file works. I copy and paste the JUnit 5 annotations from the new file to my existing file, and it still doesn't work. I am beginning to wonder if Eclipse has some configuration info somewhere behind the scenes of which I am unaware.
I was using
import org.junit.Test;
instead of
import org.junit.jupiter.api.Test;
which triggered the JUnit 5 runner to think it was working with a JUnit 4 file.
Easy solution, but hard to find since no errors messages were generated, and the file still ran. Also made more mystifying because "Organize Imports" added the JUnit 4 Test
class, and not the jupiter Test
class.
Try to change it to static
.
The @BeforeAll
method must be static
unless the test class is annotated with @TestInstance(Lifecycle.PER_CLASS)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With