Ant 构建 - Emma 代码检测 - JUnit 测试需要接口,Emma 不检测它们

发布于 2024-09-08 02:15:01 字数 385 浏览 1 评论 0原文

我有一个 Ant 构建文件,可以在其中编译应用程序和测试的 Java 源代码、检测应用程序类、运行 JUnit 测试并生成 JUnit 和 Emma 代码覆盖率报告。 JUnit 任务被赋予了检测类的路径。

问题是接口没有被检测(Emma FAQ),但我使用它们在测试中,而 JUnit 找不到它们。

我可以想到 2 个解决方案:

  • 不要在测试中使用接口(违背接口编程 - 它在测试中计数吗?)
  • 将接口复制到检测类旁边(硬编码接口的路径)

我应该如何处理并解决这个问题?

I have an Ant build file where I compile the Java source code of the application and of the tests, instrument the application classes, run JUnit tests and generate JUnit and Emma code coverage reports. The JUnit task is given the path to the instrumented classes.

The problem is that the interfaces are not instrumented (Emma FAQ) but I use them in the tests and JUnit can't find them.

I can think of 2 solutions:

  • don't use interfaces in tests (goes against programming to interfaces - does it count in tests?)
  • copy the interfaces next to the instrumented classes (hard-coding the path to the interfaces)

How should I approach and solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋风の叶未落 2024-09-15 02:15:02

在我看来,您似乎是在说 JUnit 遇到麻烦是因为接口不在类路径上?

通常的答案是将它们放在那里。

快速而肮脏的答案可能是将未检测类的类路径放入已检测类的路径之后的联合类路径中。类加载器应该使用它找到的第一个匹配项,因此将使用已检测的实现而不是未检测的实现,但接口仍然可用。

如果这解决了您的问题,您可能希望用更健壮的东西替换快速和肮脏的东西,例如使接口在与实现分离的 jar 中可用。

It sounds to me as though you are saying that JUnit is having trouble because the interfaces are not on the class path?

The usual answer would be to put them there.

The quick and dirty answer might be to put the classpath for the not instrumented classes into the juint class path AFTER the path to the instrumented classes. The class loader should use the first match it finds, so the instrumented implementations will be consumed instead of the non-instrumented implementations, but the interfaces will still be available.

If that solves your problem, you may want to replace the quick and dirty with something more robust, like making the interfaces available in a jar that is separate from the implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文