JUnit tests pass but PIT says the suite isn't green

…衆ロ難τιáo~ 提交于 2019-12-03 04:40:56

The common causes of tests failing at the coverage stage are

  1. PIT picking up tests not included/are excluded in the normal test config
  2. Tests rely on an environment variable or other property set in the test config, but not set in the pitest config
  3. Tests have a hidden order dependency that is not revealed during the normal test run
  4. PIT doesn't like something in your tech stack - possibly a JUnit test runner

It sounds like you've eliminated 1 & 2. so that leaves 3 and 4.

Test order dependencies can be hard to spot. If the answer is yes to any of these you may have one.

  • Does your codebase include mutable static state? (e.g in singletons)
  • Do your tests hit a database (in memory or otherwise) where it is possible for state to persist between tests?
  • Do your tests modify files on disk?

There are probably also many other causes not listed above.

If you are confident that order dependencies are impossible in your code base, that leaves a problem with these particular tests.

It's hard to guess what this might be without some code. Can you post a simplified version of the test that still fails?

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