sunxca
sunxca

Reputation: 135

Type mismatch junit5 @ExtendWith

so this is probably a really dumb question but I just started to migrate a project from junit 4 to 5 and saw that @RunWith() does not longer exists. It is replaced by @ExtendWith. So I tried to do it like this:

import org.jboss.arquillian.junit.Arquillian;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;

import de.msggillardon.services.journal.JournalService;
import de.msggillardon.system.UserContext;
import de.msggillardon.util.ITDeployment;

@ExtendWith(Arquillian.class)
.....

And I get the following exception: "Type mismatch: cannot convert from Class to Class <? extends Extension>

I am a really bloody beginner and have no Idea how I can fix the problem.. So maybe someone could help me or tell me where I can find the necessary Information.

Thank you all.

Upvotes: 0

Views: 1289

Answers (2)

Abdullah Gheith
Abdullah Gheith

Reputation: 520

Arquillian now support junit 5.

Replace

@RunWith(Arquallian.class) 

with

@ExtendWith(ArquillianExtension.class)

Also add the new dependency

<dependency>
        <groupId>org.jboss.arquillian.junit5</groupId>
        <artifactId>arquillian-junit5-container</artifactId>
        <version>1.7.0.Alpha10</version>
    </dependency>

Upvotes: 0

rieckpil
rieckpil

Reputation: 12031

Unfortunately, you can't use JUnit 4's Runner as your JUnit Jupiter (part of JUnit 5) extensions. That's a completely new API and not compatible.

Although the JUnit Jupiter programming model and extension model will not support JUnit 4 features such as Rules and Runners natively, it is not expected that source code maintainers will need to update all of their existing tests, test extensions, and custom build test infrastructure to migrate to JUnit Jupiter. From the official JUnit documentation

So for each @RunWith, you need to use/include the JUnit Jupiter extension. In your particular case of Arquilian, I'm not quite sure if there is already an official extension for this.

The following links might help:

Upvotes: 2

Related Questions