问题
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:
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)
回答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