Skip to main content
Jump to: navigation, search

Tycho/How Tos/JUnit5

< Tycho‎ | How Tos

Creating a new JUnit5 Test Plugin

1.) Create a new Plugin Project (e.g. ""). Add a pom.xml file to the root of your project. You do not need to do that if your project is set up for a pom-less build. If your other bundles are already using Tycho you might also want to reference a parent pom. Make sure that the parent pom does use Tycho version 1.2 or above and that the Eclipse repository your are referencing is Eclipse Oxygen or above (needed to get the Junit5 API libraries). The "" pom file would look like:

<?xml version="1.0" encoding="UTF-8"?>





2.) In order to use JUnit5 Classes, you have to import the JUnit libraries. Open the MANIFEST.MF file in the MANIFEST Editor and switch to the "Dependencies" Tab. Under "Import Packages" add the following 2 packages:

org.junit (4.12.0)
org.junit.jupiter.api (5.0.0)

The MANIFEST.MF file of the "" Plugin would look like:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bar
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.junit;version="4.12.0",

Note that you must import the packages and could not add the JUnit5 dependencies as required bundle dependency. The Juni4 dependency is needed if you want to run JUnit4 and JUnit5 tests.

3.) Create a new Test class, e.g. "":


import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class FooTest {

	public void junit5Test() {


4.) Build and Run the tests by calling

 mvn clean verify 

in the Test Plugin directory and you should get results like:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 sec - in
junit5Test  Time elapsed: 0.007 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] All tests passed!

Using JUnit5 in existing JUnit4 Test Plugins

Tycho Surefire does include the junit-vintage-engine and so you could mix JUnit4 and JUnit5 Tests in the same Test Plugin. In order to use JUnit5 in an existing JUnit4 Test Plugin, import the org.junit.jupiter.api package in the Test Plugins MANIFEST.MF (Do not remove any JUnit4 dependency). Original :

Require-Bundle: org.junit;bundle-version="4.12.0"

With JUnit5 import:

Import-Package: org.junit.jupiter.api;version="5.0.0"
Require-Bundle: org.junit;bundle-version="4.12.0"

Note: When using new JUnit5 features like for example the assertion grouping with assertAll(), you need to import additional packages to make the Tycho build succeed. To use the assertAll() feature the following imports need to be specified:

Import-Package: org.junit.jupiter.api;version="5.5.1",

Make sure that you do use Tycho version 1.2 or above and that your referenced Eclipse p2 repository contains the JUnit5 libraries (e.g. Eclipse Oxygen or above):


Back to the top