如何让 Cobertura/Emma 与 Eclipse 应用程序完美配合?
我的公司正在升级我们的构建系统以使用 Buckminster(进展顺利)。 当然,如果我们能够在我们处理代码时自动生成他们用于代码的一些指标,那么经理们自然会喜欢它 - 其中一个指标是单元测试的覆盖率。
之前的构建基于 PDE,产生了一个单独的无头应用程序,该应用程序解析上下文中的所有插件,在其中查找测试类,将所有测试用例放入一个更大的套件中,然后通过 以编程方式运行它>JUnitResultFormatter.startTestSuite()
。 在此过程中,它添加了一些针对特定元数据(版权标记等)的本地测试以及包依赖性测试。
看来我应该能够导出测试应用程序的产品,使用我选择的覆盖工具对其进行检测,然后运行它; 然而,看起来这两个覆盖工具都想知道它们正在处理的整个类路径。 是否有可能使这些工具中的任何一个都能很好地发挥作用,而无需在整个构建工作区中寻找 jar 和依赖项?
My company is in the middle of upgrading our build system to use Buckminster (which has gone well). Naturally the managers would like it if we could automatically generate some of the metrics they use for code while we're at it - one of these metrics is coverage for the unit tests.
The previous build, which was PDE-based, resulted in a separate headless application which parses through all plugins in the context, looks inside them for test classes, tosses all test cases into a larger suite, and then runs it programmatically, via JUnitResultFormatter.startTestSuite()
. In the process it adds some homegrown tests for particular metadata (copyright markings, etc) and tests for package dependency.
It seems like I should be able to just export the product for the test app, instrument it with the coverage tool of my choice, and then run it; however, it looks like both the coverage tools want to know the entire classpath they're dealing with. Is it possible to make either of these tools play nice without trawling my entire build workspace for jars and dependencies?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在一个旧的 SO 问题的帮助下,设法让一切正常工作。
我们从这篇文章开始,为我们提供了使用 EMMA 的覆盖设置示例。 然而,我们似乎需要在每个我们想要获取覆盖率数据的插件上强制依赖 EMMA。
一些 Google 取证让我们找到这本书摘录,充分涵盖了 OSGi 类加载器层次结构。 通过将 osgi.parentClassloader=app 行添加到测试运行应用程序的 config.ini 中,我们可以在命令行上指定类路径。 该类路径需要包括:
startup.jar
当然,我们通过
Ant 任务,它会默默地忽略您提供的任何类路径信息并仅使用 jar。 在让 Emma 工作后,我们切换到 Cobertura,我们的最终 Ant 脚本(稍微删节并匿名)如下所示:希望这可以帮助那些与我们处于同一位置的人。
Managed to get everything working, with the help of an older SO question.
We started with this post, which provided us with an example coverage setup using EMMA. However, it appeared that we'd need to force a dependency on EMMA on every plugin we wanted to get coverage data for.
Some Google forensics got us to this book excerpt, which rather adequately covers the OSGi classloader hierarchy. By adding the
osgi.parentClassloader=app
line to the config.ini of the test running application, we could specify a classpath on the commandline. That classpath needed to include:startup.jar
Of course, we were running the tests via the
<java jar="foo.jar">
Ant task, which does silently ignores any classpath information you provide and uses just the jar. After we got Emma working, we switched to Cobertura, and our final Ant script (slightly abridged and anonymized) looks like:Hopefully this helps someone out who's in the same spot we were in.