19

In my project I'm doing some cleanup and decided to move everything to JUnit5.

Till this time, I was using

@RunWith(JUnitPlatform.class)

Now I want to migrate it to @ExtendWith. Is there any equivalent for this JUnitPlatform.class in JUnit5?

Szymon Żak
  • 491
  • 1
  • 3
  • 17
  • If you're wondering about `@RunWith(SpringRunner.class)` in JUnit5 see https://stackoverflow.com/questions/60369022/should-springrunner-be-used-in-spring-boot-with-junit-5 – rogerdpack Feb 11 '22 at 20:07

2 Answers2

18

You don't need it anymore when using junit 5.

In the junit documentation it states:

Annotating a class with @RunWith(JUnitPlatform.class) allows it to be run with IDEs and build systems that support JUnit 4 but do not yet support the JUnit Platform directly.

So since you are migrating to junit 5 I suppose your build system/IDE supports it. Hence, you don't need the annotation anymore.

Dries Thieren
  • 221
  • 2
  • 5
  • Ok, thanks. I have another fast question. CamelSpringBootRunner and CamelSpringRunner aren't migrated yet and I can't just simply delete it like JUnitPlatform? – Szymon Żak Aug 12 '19 at 14:17
  • 1
    You won't be able to migrate those to junit 5 then. – Dries Thieren Aug 12 '19 at 14:54
  • 1
    (until Camel decides to resolve this issue: https://issues.apache.org/jira/browse/CAMEL-11807) – Dries Thieren Aug 12 '19 at 15:03
  • 5
    so what would I do if I wanted to run an android project test with Robolectric? I usually would do `@RunWith(RobolectricTestRunner::class)` – Fabio Feb 27 '20 at 22:26
2

Junit4 @RunWith has been replaced by @ExtendWith in JUnit5 as of content from https://www.baeldung.com/junit-5-runwith

Ceddaerrix
  • 304
  • 1
  • 14