问题
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?
回答1:
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)
来源:https://stackoverflow.com/questions/50565724/are-test-suites-considered-deprecated-in-junit5