Are test suites considered deprecated in JUnit5?
Asked Answered
S

2

47

I am trying to create test suites with JUnit5. After some research I was not able to conclude whether it is a supported feature or not.

The official user guide only mentions suites with regard to backwards compatibility to JUnit 4.

This is how it was done back in JUnit 4:

@RunWith(Suite.class)
@SuiteClasses({Test1.class, Test2.class})
public class TestSuite {
}

Does this mean, that Test Suites are considered deprecated now, or is the same concept still available under another name?

Samora answered 28/5, 2018 at 11:48 Comment(6)
As far as I am aware you should use @SelectClasses and @SelectPackages.Athiste
The feature is not implemented yet: github.com/junit-team/junit5/issues/744Saker
@Nebula, does my answer answer your question?Wealth
@SamBrannen yes, thank you for the detailed explanationSamora
thought @Tags is replacement for suites?Sarraute
@SamBrannen - So, if test suites matter a lot to me, then should I continue using TestNg until Junit5 allows test suites ?Bozo
W
37

Does this mean, that Test Suites are considered deprecated now, or is the same concept still available under another name?

Bitter Suite Answer:

There is in fact support for test suites in JUnit 5, but it's almost certainly not what you're looking for. However, the JUnit Team is working on something that will likely suit your needs.

Detailed Answer:

As of JUnit 5.2, the only built-in support for suites is via the JUnitPlatform Runner (registered via @RunWith(JUnitPlatform.class)). That runner actually launches the JUnit Platform (a.k.a., JUnit 5 infrastructure) and allows you to execute tests against various programming models such as JUnit 4 and JUnit Jupiter. It also allows you to select various things (e.g., classes, packages, etc.) and configure include and exclude filters (e.g., for tags or test engines).

The problem with the runner is that it can not be executed directly on the JUnit Platform. It can only be executed using JUnit 4 by itself. That means that you lose the full reporting capabilities of the JUnit Platform since information is lost in translation from the JUnit Platform to JUnit 4.

In summary, you can technically use the JUnitPlatform runner to execute a suite using JUnit 5, and the tests will execute, but the reporting and display in an IDE will be suboptimal.

On the bright side, the JUnit Team plans to provide built-in support for suites in JUnit 5 that does not suffer from the shortcomings of the JUnitPlatform runner for JUnit 4. For details, see all issues assigned to the "suites" label on GitHub.

In addition, there is already a feature branch that you can check out which can be consumed in a Maven or Gradle build via JitPack.

Regards,

Sam (JUnit 5 core committer)

Wealth answered 4/6, 2018 at 10:7 Comment(0)
H
20

Test suits can now be run with JUnit 5 suite engine (from version 5.8.0).

// Aggregator dependency for junit-platform-suite-api and junit-platform-suite-engine
implementation("org.junit.platform:junit-platform-suite:1.9.1")

Here is the code for Kotlin (replace ::class with .class for Java):

import org.junit.platform.suite.api.*

@Suite
@SelectClasses(MyTestClass1::class, MyTestClass2::class)
@SelectPackages("...")
@SelectDirectories("...")
class MyTestSuite

The deprecation of JUnitPlatform runner:

The introduction of @Suite support provided by the junit-platform-suite-engine module makes the JUnitPlatform runner obsolete. See JUnit Platform Suite Engine for details.

Heidt answered 13/9, 2021 at 19:31 Comment(1)
I'd like to mention that test classes can be both JUnit4 and/or JUnit 5Risner

© 2022 - 2024 — McMap. All rights reserved.