5

I have created multiple Test case java files in eclipse and version of JUnit is JUnit5.

Now, I am trying to create a Junit TestSuite through the eclipse GUI and during the creation, I am not seeing the JUnit5 in the available versions.

This is the sample code that I have written for creation of TestSuite.

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.IncludeClassNamePatterns;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@IncludeClassNamePatterns(".*Tests?")
@IncludeEngines("junit-jupiter")

public class AllTests {
}

This is the error I am getting while executing.

enter image description here

Should I do any manual setting to be able to create/run test suites?

enter image description here

techrhl
  • 434
  • 8
  • 19

2 Answers2

2

When executing tests in a class annotated with @RunWith, that class is technically a JUnit 4 test class.

Thus, you have to execute your test suite using the "JUnit 4 Runner" in the "Run Configurations" of Eclipse.

See the following Eclipse bug for more information: https://bugs.eclipse.org/bugs/show_bug.cgi?id=512772

Regarding the "JUnit Test Suite" dialog, that won't help you if you are using @RunWith(JUnitPlatform.class) to execute a suite in JUnit 5.

Sam Brannen
  • 29,611
  • 5
  • 104
  • 136
  • 1
    Then what will be the way to create test suite in JUnit5? – techrhl May 27 '18 at 06:57
  • If you are using `@RunWith(JUnitPlatform.class)` that is technically a suite in JUnit 5. It is just that it uses JUnit 4 to _launch_ the JUnit 5 Platform. – Sam Brannen May 28 '18 at 10:06
  • Note, however, that we have plans to provide first-class support for suites in JUnit 5 that do not require a JUnit 4 _Runner_. For details, see all issues labeled with _suite_ in GitHub: https://github.com/junit-team/junit5/issues?q=is%3Aopen+is%3Aissue+label%3A%22theme%3A+suites%22 – Sam Brannen May 28 '18 at 10:06
0

you are not using JUnit5, Junit5 FQN is org.junit.jupiter.api.*

see https://www.eclipse.org/community/eclipse_newsletter/2017/october/article5.php

Andre Brito
  • 146
  • 8