解决Junit Vintage和Custom Junit Engine之间的冲突
我正在研究一个应该与Junit 4和Junit 5都兼容的(经过量身定制的)测试框架。
因此,我有一个自定义的Junit 4 Runner 和 一个自定义的Junit 5引擎,都有能力根据测试类 /方法的自定义注释发现测试用例。
一切都很好,如果最终用户使用Junit 4或使用仅使用 使用junit 5进行测试。
但是,当用户在自定义引擎中还包括外,还会出现问题。由于测试符合两种发动机的检测资格,因此它们正在运行两次。
假设我无法更改当前方法(自定义测试跑者 +自定义Junit 5引擎),那么解决此问题的最简单方法是什么?
我想我正在沿着:
public final class CustomTestEngine extends HierarchicalTestEngine<CustomEngineExecutionContext> {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
if (someJUnitApi.getDetectedEngines().contains(JUnitVintageEngine.class)) {
// skip tests contained in JUnit 4 test classes - JUnit Vintage will take care of them
}
}
}
somejunitapi.getDetectedEngines()()
需要覆盖所有基础:引擎自动检测/禁用,应用的发动机过滤器,添加到其他测试引擎添加到启动器等
(我知道我可以无条件地应用,如果
零件无条件,则强度强迫用户使用老式,如果他们想要@runwith
- 注释的测试才能完全运行,但我只愿意将该选项视为衡量最后的度假胜地)
I am working on a (heavily customized) test framework that is supposed to be compatible with both JUnit 4 and JUnit 5.
Therefore, I have a custom JUnit 4 runner and a custom JUnit 5 engine, both capable of discovering test cases, based on a custom annotation on the test class / method.
Everything works perfectly fine, if the end user runs their test using JUnit 4 or using JUnit 5 with only the custom engine included.
However, problems arise when the user includes JUnit Vintage in addition to the custom engine. Since the tests are eligible for detection by both engines, they are being run twice.
Assuming I cannot change the current approach (custom test runner + custom JUnit 5 engine), what would be the easiest way to solve this problem?
I guess I'm looking for sth along the lines of:
public final class CustomTestEngine extends HierarchicalTestEngine<CustomEngineExecutionContext> {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
if (someJUnitApi.getDetectedEngines().contains(JUnitVintageEngine.class)) {
// skip tests contained in JUnit 4 test classes - JUnit Vintage will take care of them
}
}
}
Where someJUnitApi.getDetectedEngines()
needs to cover all the bases: engine auto-detection enabled/disabled, applied engine filters, additional test engines added to the launcher etc.
(I know I could just apply the if
part unconditionally, esentially forcing the user to use Vintage if they want their @RunWith
- annotated tests to run at all, but I am only willing to consider that option as a measure of last resort)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论