junit:forkMode=“一次"的影响关于测试正确性 [英] junit: impact of forkMode="once" on test correctness

查看:25
本文介绍了junit:forkMode=“一次"的影响关于测试正确性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想减少我们的构建(使用 ant)运行测试所需的时间.目前我正在使用默认的 forkMode,它分叉一个新的vm 在每个测试类上 (perTest).

I'd like to reduce the time which our build (using ant) takes for running the tests. Currently I am using the default forkMode, which forks a new vm on each test class (perTest).

我正在考虑切换到 forkMode="once" 但我不确定这是否会以某种方式耦合测试,并且可能会给我误报和/或错误运行我的测试后结果为阴性.

I am thinking about to switch to forkMode="once" but I am unsure if this will couple the tests somehow and maybe give me false positive and/or false negatives results after running my tests.

问题:

  1. 每个测试用例是否会获得一个新的类加载器,以便之前运行的所有静态引用不再可访问/可见?

  1. Will each test case get a new ClassLoader so that all static references from previous runs are not accessible/visible anymore?

是否有其他事情导致测试依赖/测试方法的耦合可能改变行为(除了我没有使用的本地库加载)

Are there other things which lead to test dependency/coupling of test methods which may change the behavior (beside native library loading which I am not using)


更新

根据当前的答案,在使用 forkMode 时,junit 似乎总是在每个 vm/fork 的所有测试用例之间共享一个类加载器.(所以 forkMode="once" 确实意味着所有测试都有一个类加载器)

According to the current answers it seems that junit is always sharing a single classloader between all test cases per vm/fork when using forkMode. (so forkMode="once" indeed means there's one classloader for all tests)

这有很多优点(更快的测试并且可能由于静态耦合而导致测试失败)但也有一些缺点(静态耦合仅在使用共享类加载器时才有效 -> 误报)

This has many advantages (faster tests and may cause tests to fail because of static coupling) but also some disadvantages (static coupling which will only work if a shared classloader is used -> false positive)

推荐答案

  1. 测试运行器将有效地为您的所有测试创建一个套件并运行它们 - 这样只涉及一个类加载器.
  2. 是的,这意味着静态数据将在测试之间共享,这有时会很方便,但会迫使您减少子句之间的静态耦合,这是一件好事.
  3. 通常没有任何明确的 GC,但您可以自己做.

通常在一个 VM 中运行所有测试是一件好事.它迫使您查看静态耦合,而且速度要快得多.至关重要的是,这也是您的 IDE 运行它们的方式,这确实是测试应该运行的方式 - 尽可能接近您编译的频率.

Generally running all your tests in one VM is a good thing. It forces you to look at static coupling and is a lot quicker. Crucially, it's also the way that your IDE will be running them, and that really is the way that tests should be run - as close as possible to as often as you compile.

这篇关于junit:forkMode=“一次"的影响关于测试正确性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆