Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent for @RunWith(JUnitPlatform.class) for JUnit5

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?

like image 318
Szymon Żak Avatar asked Aug 12 '19 13:08

Szymon Żak


People also ask

What is @RunWith JUnitPlatform class?

Class JUnitPlatform 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. Consult the various annotations in the org. junit.

What is @RunWith in JUnit 5?

In JUnit 5, the @RunWith annotation has been replaced by the more powerful @ExtendWith annotation. However, the @RunWith annotation can still be used in JUnit 5 for the sake of backward compatibility.

Does Powermock work with JUnit5?

Power mock is not compatible with JUnit5 So we will discuss it will JUnit4.

What is JUnitPlatform?

The JUnit Platform serves as a foundation for launching testing frameworks on the JVM. It also defines the TestEngine API for developing a testing framework that runs on the platform.


2 Answers

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.

like image 64
Dries Thieren Avatar answered Oct 18 '22 21:10

Dries Thieren


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

like image 35
Ceddaerrix Avatar answered Oct 18 '22 20:10

Ceddaerrix