JUnit的:;一旦&QUOT forkMode = QUOT的影​​响;在测试的正确性 [英] junit: impact of forkMode="once" on test correctness

查看:207
本文介绍了JUnit的:;一旦&QUOT forkMode = QUOT的影​​响;在测试的正确性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以减少我们的构建(使用ANT)花费运行测​​试的时间。
目前我使用的是默认 forkMode ,该叉每个测试类新的VM perTest )。

我想切换到 forkMode =曾经但我的不能确定这是否将夫妻测试不知何故,也许给我运行我的测试后,假阳性和/或假阴性结果。

问题:


  1. 将每个测试用例得到一个新的ClassLoader ,以便从previous运行所有静态引用不可访问/可见了吗?


  2. 是否有其他的事情从而导致测试的测试方法可能改变行为


  3. 关于垃圾收集/最终确定什么,是他们每次测试之后运行? (我不靠他们,但我只想得到一个完整的画面)

结果
更新

根据当前答案似乎的junit总是共享每个VM /叉所有测试用例使用forkMode时之间的单个类加载器。
(所以forkMode =曾经的确意味着有所有测试一个类装载器)

这有许多优点(更快的测试,并可能导致测试,因为静态耦合的失败),但也有一些缺点(其将唯一的工作,如果使用一个共享的类加载器静态耦合 - >假阳性)


解决方案

  1. 测试运行将有效地使所有测试的单个套件并运行它们 - 所以,只有一个类加载器是参与

  2. 是的,这意味着静态数据的测试,它可以偶尔得心应手之间共享,但将迫使你削减子句之间的静态耦合,这是一件好事。

  3. 没有一般任何明确的GC,但你可以做你自己的。

一般来说,在一个虚拟机上运行所有测试是一件好事。它迫使你看静态耦合是快了很多。最重要的是,它也是你的IDE将运行它们的方式,那实在是一个测试应该运行的方式 - 尽量靠近,以尽可能多编译

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

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.

Questions:

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

  2. 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)

  3. What about garbage collection/finalization, are they run after each test? (I don't rely on them, but I just want to get a complete picture)


UPDATE

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. The test runner will effectively make a single Suite of all of your tests and run them - so that only one classloader is involved.
  2. Yes that means that static data will be shared between tests, which can occasionally be handy, but will force you to cut down on the static coupling between clauses, which is a good thing.
  3. There isn't generally any explicit GC, but you can do your own.

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的:;一旦&QUOT forkMode = QUOT的影​​响;在测试的正确性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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