gpt4 book ai didi

maven - 在 Surefire Maven 插件中 fork : is it safe to use forking?

转载 作者:行者123 更新时间:2023-12-05 07:54:52 25 4
gpt4 key购买 nike

我们有several options在 Maven Surefire 插件中描述 fork 。其中一个选项,forkCount,解释如下:

Option to specify the number of VMs to fork in parallel in order to execute the tests. When terminated with "C", the number part is multiplied with the number of CPU cores. Floating point value are only accepted together with "C". If set to "0", no VM is forked and all tests are executed within the main process.

基于此,我可能会猜测,如果使用 fork 机制并重用 fork (reuseForks=true),那么同一个 JVM 将用于多个测试。这意味着,如果我已将某个类加载到内存中,则该类的静态成员可以在其他测试中重用并意外失败。

我的理解正确吗?

最佳答案

你是对的。使用静态元素的测试不是线程安全的,应该是 excluded from parallel execution :

If the Suite or Parameterized is annotated with @NotThreadSafe, the suite classes are executed in single thread. You can also annotate individual test class referenced by Suite, and the other unannotated test classes in the Suite can be subject to run in parallel.

Note: As designed by JUnit runners, the static methods annotated with @BeforeClass and @AfterClass are called in parent thread. Assign classes to the @NotThreadSafe Suite to prevent from this trouble.

关于maven - 在 Surefire Maven 插件中 fork : is it safe to use forking?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30874967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com