简体   繁体   English

如何以并行模式运行有序的 JUnit5 测试

[英]How to run ordered JUnit5 tests in parallel mode

I have a need to run dependent tests (not unit, but long UI-scenarios with selenium).我需要运行依赖测试(不是单元,而是带有 selenium 的长 UI 场景)。 There are reasons related to the environment, because of which I have to prepare a "random" state, and use this state in other tests.有与环境有关的原因,因此我必须准备一个“随机”的state,并在其他测试中使用这个state。 To do this, I perform a series of actions, after which I get a link, save it to a static String variable in a method annotated as @Order (1).为此,我执行了一系列操作,之后我得到一个链接,将其保存到一个 static 字符串变量中,该方法使用注释为 @Order (1) 的方法。 After that, in methods annotated by @Order (2 and more), the link stored in the static String variable is available之后,在@Order 注释的方法中(2 和更多),存储在 static 字符串变量中的链接可用

Usually the order is random, but if you follow the manual , then in one thread everything works great.通常顺序是随机的,但是如果您按照手册进行操作,那么在一个线程中一切都会很好。

The number of tests is quite large, so it seemed logical to run them in parallel.测试的数量非常大,因此并行运行它们似乎是合乎逻辑的。 It's no problem for 5.3 and newer version. 5.3及更新版本没问题 I use "Configuration parameters to execute top-level classes in parallel but methods in same thread".我使用“配置参数并行执行顶级类,但在同一线程中执行方法”。 For ordinary test classes it works like that.对于普通的测试类,它是这样工作的。 And now the problem.而现在的问题。 Just add the @Execution(ExecutionMode.CONCURRENT), how the order stops working.只需添加@Execution(ExecutionMode.CONCURRENT),订单如何停止工作。 Because of this, instead of link in a static variable, I get null.因此,我得到的是 null,而不是 static 变量中的链接。 Is it possible to fix it?有可能修复它吗?

Thank you in advance先感谢您

Pretty noob mistake.相当菜鸟的错误。 It turned out to be enough to add annotation @Execution(ExecutionMode.SAME_THREAD) to each method that should be executed in the same thread as the parent.事实证明,将注解 @Execution(ExecutionMode.SAME_THREAD) 添加到每个应该在与父线程相同的线程中执行的方法就足够了。

It's not entirely clear what the settings do in junit-platform.properties.尚不完全清楚 junit-platform.properties 中的设置有什么作用。 But perhaps I wishful thinking by reading the manual.但也许我通过阅读手册一厢情愿。 It took half a day to understand this (((花了半天时间才明白这一点(((

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM