junit: how to avoid false positives when using forkMode=“once”?

旧时模样 提交于 2019-12-14 03:55:36

问题


I'd like to speed up junit tests and I think about using forkMode="once".

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.

I've got two questions regarding this:

  1. 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.

  2. Is it easily possible to randomize test order to decrease the probability of false positives (using ant)


回答1:


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.



来源:https://stackoverflow.com/questions/6321473/junit-how-to-avoid-false-positives-when-using-forkmode-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!