RoiEX
RoiEX

Reputation: 1235

Eclipse JUnit 5 support

Currently, JUnit 5 is just out with a "stable" version. IntelliJ supports JUnit 5 according to the Website. My question is if eclipse is supporting JUnit 5 as well, and if not when it is going to be supported. With supported I mean if I can run JUnit 5 tests without the need for a @RunWith(PlatformRunner.class) annotation.

EDIT October 2017: Eclipse now officially supports JUnit 5 as of Eclipse Oxygen1.a (4.7.1a)

Upvotes: 13

Views: 23609

Answers (4)

MustardMan
MustardMan

Reputation: 111

Upgrade

I wrestled with this for a while. I want to contribute to a project using junit 5 tests, but I was using an older version of Eclipse Neon.

I have access to a different machine where the junit 5 tests were working. It seems the more updated versions of Eclipse come with junit 5 functioning. I went to: https://www.eclipse.org/eclipseide/

Installing the newer version and then loading the project from github took care of the issue. I found that on that other computer it was on version 2021-06 but doing it a simple upgrade (with major upgrades enabled) brought it up to 2021-12 which matches the latest as of the time of writing this answer.

I anticipate this helping me not have issues with with managing updates and upgrades in the future.

Since summer 2021 the approach for integrating Eclipse with GitHub has changed. See this post.

how to - github two factor authentication with eclipse

Upvotes: 0

Aaron Waddell
Aaron Waddell

Reputation: 11

quick note: make sure you are using the jupiter Test annotation (org.junit.jupiter.api.Test) and not the old junit.test (junit4). I wasted several hours trying to get my test to run on junit 5 because of this!

Upvotes: 1

Phoenix
Phoenix

Reputation: 1349

You can run JUnit 5 tests in Eclipse 4.7 Oxygen after installing the JUnit 5 Support (BETA) for Oxygen 4.7 plugin that you can find in the Eclipse Marketplace. After a complete Eclipse restart, open your project properties at

Java Build Path -> Libraries -> Add Library -> JUnit -> JUnit 5

Upvotes: 11

Arpit Aggarwal
Arpit Aggarwal

Reputation: 29276

With Eclipse Kepler Service Release 2, you can run JUnit 5 tests after annotating the class with @RunWith(JUnitPlatform.class) as follows:

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
public class Junit5Demo {

    @DisplayName("First Test")
    @Test
    void firstTest() {
        assertEquals(1, 1);
    }
}

enter image description here

pom.xml of the project is as follows:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>arpit.aggarwal.junit5.demo</groupId>
    <artifactId>junit5-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <junit.jupiter.version>5.0.0-M2</junit.jupiter.version>
        <junit.vintage.version>4.12.0-M2</junit.vintage.version>
        <junit.platform.version>1.0.0-M2</junit.platform.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <includes>
                        <include>**/Test*.java</include>
                        <include>**/*Test.java</include>
                        <include>**/*Tests.java</include>
                        <include>**/*TestCase.java</include>
                    </includes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>${junit.platform.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit.vintage.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>${junit.platform.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Upvotes: 7

Related Questions