在Tycho项目中为非OSGi JUnit测试添加仅测试依赖关系 [英] Adding test-only dependencies for non-OSGi JUnit test in a Tycho project

查看:125
本文介绍了在Tycho项目中为非OSGi JUnit测试添加仅测试依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个使用Eclipse Tycho构建的OSGi包。所有代码依赖关系都是首先管理的。



现在我想开发一些纯JUnit测试来测试bundle的内部功能。这些测试不需要一个OSGi容器来执行,但是它们确实需要Mockito。



由于Mockito显然只有当这个非OSGi测试是正在运行而不是在执行捆绑包本身时,将依赖关系添加到MANIFEST.MF文件感到错误。



我目前的做法是我添加了一个项目/ lib文件夹,其中包含mockito.jar,并且我手动将此jar添加到他的类路径。这个工作适用于本地的eclipse执行,这是暂时的。



问题是,每个同事都需要将jar添加到类路径中。类路径文件显然没有被检入。此外,我猜测当最终执行测试时会出现问题在构建服务器上,因为缺少类路径条目。



所以我的问题是:如何添加依赖关系到Mockito的方式,将为每个同事努力,在捆绑执行期间不会引起任何问题?



我可以将其添加为MANIFEST.MF文件的可选依赖关系,但如上所述,它不觉得这是正确的解决方案。



我可以将mockito依赖关系作为正常的pom-first依赖关系添加到范围 test 或这是否会与正常的清单第一种方法相冲突?



我还发现了 maven-eclipse-plugin 提供一个 classpathContainers 配置选项,但是我没有找到类似的选项来添加库到类路径。



测试位于捆绑包本身的src / test / java文件夹中。



什么是最新的方法来添加测试唯一依赖项目构建与eclipse Tycho因为我技术上不需要Tycho来执行这些测试?

解决方案

如果您可以使用类路径运行测试完全只是构成Maven依赖(例如到Mockito),您还可以为这些测试创建一个包含 jar 的模块。从该模块中,您还可以向该包添加一个依赖关系,然后将其用作纯JAR。



在这种情况下,您会松动的是分辨率的传递依赖。然后,Maven将解决 jar 项目,Maven不知道OSGi软件包的清单依赖关系。但是,根据您想要测试的确切性质,这可能仍然有效。


I have several OSGi-bundles that I build with Eclipse Tycho. All code dependencies are managed manifest-first.

Now I want to develop some pure JUnit-Tests in order to test bundle-internal functionality. These tests do not need an OSGi-container in order to be executed, but they do need Mockito.

As Mockito obviously is only needed when this non-OSGi-tests are being run and not during the execution of the bundle itself, it feels wrong to add the dependency to the MANIFEST.MF file.

My current approach is that I added a project/lib-folder that holds the mockito.jar and that I added this jar to his classpath manually. This works for local eclipse execution, which is fine for the moment.

The problem is, that every coworker needs to add the jar to the classpath as well, as the .classpath-file is obviously not checked in. Also, I guess that there will be problems when the tests eventually will be executed e.g. on a build server because of the missing classpath entry.

So my question is: How can I add the dependency to Mockito in a way that will work effortless for every coworker and will not cause any problems during bundle execution?

I could add it as optional dependency to the MANIFEST.MF-file, but as stated above, it doesn't feel like thats the correct solution.

Can I add the mockito-dependency as normal pom-first dependency with scope test or will this cause conflicts with the normal manifest-first approach?

I also found the maven-eclipse-plugin which offers a classpathContainers configuration option, but I did not find a similar option to add a library to the classpath.

The tests are located in the src/test/java folder of the bundle itself.

What is the best way to add test-only dependencies to a project built with eclipse Tycho, given that I technically don't need Tycho in order to execute those tests?

解决方案

If you can run your test with a class path that you completely only compose of Maven dependencies (e.g. to Mockito), you could also create a module with jar packaging for these tests. From that module, you'd also add a dependency to the bundle, which would then be used as plain JAR.

What you'd loose in this case is the resolution of transitive dependencies. The jar project would then be resolved by Maven, and Maven doesn't know about the Manifest dependencies of the OSGi bundle. But depending on the exact nature of what you want to test, this may still work.

这篇关于在Tycho项目中为非OSGi JUnit测试添加仅测试依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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