英文:
Running JUnit tests and forking the JVM correctly (Ant)
问题
我最近开始将JUnit 4升级到JUnit 5,然后升级到Ant 1.10.8。
当我运行测试时,我看到的情况是,似乎我们没有像以前的版本那样分叉JVM。结果表明,我们在测试之间重复使用JVM,这意味着我们在运行之间会遇到静态类的问题。
<junitlauncher>
<classpath>
...
</classpath>
<testclasses>
<fork dir="${baseDirectory}">
....
</fork>
</testclasses>
</junitlauncher>
我是否遗漏了Ant上的分叉功能?还是有没有其他方法可以像“旧的ant和junit组合”那样运行?
英文:
I've recently started the upgrade from JUnit 4 to JUnit5 and the subsequent update to Ant 1.10.8 as well.
What I'm seeing when I run the tests is that it appears we're not forking the JVM like it did in previous versions. The results are indicating that we're reusing the JVM between tests which means we're hitting issue with static classes between runs.
<junitlauncher>
<classpath>
...
</classpath>
<testclasses>
<fork dir="${baseDirectory}">
....
</fork>
</testclasses>
</junitlauncher>
Is there something I'm missing here with the fork functionality on Ant?
Or is there another way around this that operates like the 'old ant & junit combo'?
答案1
得分: 2
*sigh
所以对于那些感兴趣的人 - 答案在细节中:
fork嵌套元素可用于在新分叉的JVM中运行测试。
此testclasses元素的所有测试将在新分叉的JVM的一个单一实例中运行。
因此,JUnit5不会为每个测试分叉 - 它会为testclasses属性中的所有项目进行分叉。为了让每个测试类都有一个JVM来循环遍历资源 - 需要在testclasses块的外部进行一些魔法。
英文:
*sigh
So for those interested parties - the answer is in the details:
> 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.
So JUnit5 doesn't fork for each test - it forks for all the items in the testclasses attribute. In order to have a resource to be looped through with a JVM for each test class - that is going to require some magic on the outside of that testclasses block.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论