Java 具有Eclipse扩展API的OSGi测试片段依赖项
如果我理解正确,建议在OSGi中进行白盒测试的方法是向需要测试的包中添加(测试)片段。我有以下设置:Java 具有Eclipse扩展API的OSGi测试片段依赖项,java,dependencies,osgi,eclipse-rcp,Java,Dependencies,Osgi,Eclipse Rcp,如果我理解正确,建议在OSGi中进行白盒测试的方法是向需要测试的包中添加(测试)片段。我有以下设置: 将“com.bundleA”与包“com.bundleA.foo”捆绑 带有包“com.bundleA.foo”和“com.bundleA.utils”的片段“com.bundleA.tests” 将“com.bundleB”与包“com.bundleB.bar”捆绑 带有包“com.bundleB.bar”的片段“com.bundleB.tests” “com.bundleA”导出“com.
- 将“com.bundleA”与包“com.bundleA.foo”捆绑
- 带有包“com.bundleA.foo”和“com.bundleA.utils”的片段“com.bundleA.tests”
- 将“com.bundleB”与包“com.bundleB.bar”捆绑
- 带有包“com.bundleB.bar”的片段“com.bundleB.tests”
- “com.bundleA”导出“com.bundleA.foo”
- 'com.bundleA.tests'导出'com.bundleA.utils'
- “com.bundleB”导入包“com.bundleA.foo”
在这种情况下,最佳做法是什么?问题在于您的用例:您希望com.bundleB.tests导入com.bundleA.utils,但com.bundleA.utils是com.bundleA的一部分。为unittests创建片段是可以的,但当这些片段的一部分必须由其他捆绑包中的其他unittests使用时就不行了。
您应该创建一个仅包含必须共享的utils类(com.bundleC)的捆绑包,该类仅由unittest片段使用,并且包含com.bundleA.utils包。尽管我理解您的答案,“com.bundleC”将无法访问非导出包,但这是我的情况所必需的。此外,如果'com.bundleA.tests'依赖于'com.bundleC'(因为testutils已经移动到那里,所以它将依赖于'com.bundleC'),则会发生循环依赖。将“com.bundleC”作为一个片段将重新建立从生产代码中访问测试软件的问题。