问题描述
我想加快 junit 测试的速度,并考虑使用 forkMode="once"
.
I'd like to speed up junit tests and I think about using forkMode="once"
.
由于 junit 似乎使用共享类加载器 对于一个进程中的所有测试,除了误报(这是一件好事,因为它暴露了静态耦合),也可能出于同样的原因而出现误报.
Due to the fact that junit seems to use a shared classloader for all tests within one process beside false negatives (which is good thing because it exposes static coupling) there might be also false positives by the same reason.
关于这个,我有两个问题:
是否有可能改变 junit 中的类加载器行为以为每个测试用例强制执行一个新的类加载器?我认为能够在两个 mdo 中运行 junit 以避免误报和否定是理想的.
Is it somehow possible to alter the classloader behavior in junit to enforce a new classloader for each test case? I think it would be ideal to be able to run junit in both mdoes to avoid both false positives and negatives.
是否可以轻松地随机化测试顺序以降低误报的概率(使用蚂蚁)
Is it easily possible to randomize test order to decrease the probability of false positives (using ant)
推荐答案
据我所知不支持你想要的,但无论如何,我认为你应该重新考虑你的方法:你应该让你的代码更易于测试它不会依赖于新的 JVM/类加载器.
As far as I know what you want is not supported, but in any case, I think you should reconsider your approach: you should make your code more testable so it will not depend on a new JVM/Classloader.
但如果你不能/不会 - 你最好的做法是分叉.
But if you can't/won't - your best course of action is to fork.
这篇关于junit:如何在使用 forkMode="once" 时避免误报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!