运行 JUnit 测试并正确分叉 JVM (Ant)

Running JUnit tests and forking the JVM correctly (Ant)

我最近开始从 JUnit 4 升级到 JUnit5,随后也更新到 Ant 1.10.8。

我在 运行 测试时看到的是,我们似乎没有像以前的版本那样分叉 JVM。结果表明我们在测试之间重用 JVM,这意味着我们在 运行 秒之间遇到静态 类 问题。

<junitlauncher>
   <classpath>
      ...
   </classpath>
   <testclasses>
      <fork dir="${baseDirectory}">
         ....
      </fork>
   </testclasses>
</junitlauncher>

Ant 上的分叉功能是否遗漏了什么? 或者是否有另一种方法可以像 'old ant & junit combo'?

一样运行

*感叹

所以对于那些感兴趣的人 - 答案就在细节中:

The fork nested element can be used to run the tests in a newly forked JVM. All tests that are part of this testclasses element will run in one single instance of the newly forked JVM.

所以 JUnit5 不会为每个测试分叉 - 它会为 testclasses 属性中的所有项目分叉。为了让资源通过 JVM 循环用于每个测试 class - 这将需要在该测试 classes 块的外部使用一些魔法。