running junits and cobertura with maven

前端 未结 3 871
时光取名叫无心
时光取名叫无心 2020-12-05 23:56

In our project, we run both junits and cobertura using maven. The problem I am facing is that,

  1. junit test cases are running twice, once before the jar creatio
相关标签:
3条回答
  • 2020-12-06 00:20

    This happens because the reporting execution requires the test execution so it can create the reports. If there were a "site-only" goal on the site plugin that didn't have the @requiresDependencyResolution test annotation, it could be bound to the project's prepare-package phase and your reports would be generated without the tests running twice.

    Unfortunately there seems to currently be no such goal (see my question on the subject). See my answer to the question for details of a workaround.

    0 讨论(0)
  • 2020-12-06 00:28

    Try adding cobertura as a compile scope reference. And post the relevant parts of your pom.

    0 讨论(0)
  • 2020-12-06 00:30

    While I cannot find the exact page anymore, I recently read a discussion of why running the tests twice is considered a good idea. The key issues cited were around the effects of the Cobertura byte code alteration on the accuracy of your tests. In certain cases the timing of your code execution might be important, the byte code alteration can cause tests that fail in JUnit to pass when run only in Cobertura and vice versa. For this reason, it was recommended that the tests be allowed to execute twice. Most of the examples cited were around multi-threaded behaviors, but I imagine that there could be other cases were the byte code alteration can cause issues in your tests. Having the tests execute both ways provides you with baseline results and also reduces the chances of sending you on a wild goose chase if Cobertura is in fact altering test success.

    0 讨论(0)
提交回复
热议问题