OSGi测试片段依赖于Eclipse-ExtensibleAPI

Dav*_*Chu 5 java dependencies osgi eclipse-rcp

如果我理解正确,OSGi中建议的白盒测试方法是将(测试)片段添加到需要测试的包中.我有以下设置:

  • 使用软件包'com.bundleA.foo'捆绑'com.bundleA'
  • 使用软件包'com.bundleA.foo'和'com.bundleA.utils'片段'com.bundleA.tests'
  • 使用包'com.bundleB.bar'捆绑'com.bundleB'
  • 使用包'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'.在OSGi中,从哪里导出包并不重要.但是,Eclipse PDE需要'com.bundleA'中的'Eclipse-ExtensibleAPI = true'才能理解'com.bundleA.tests'可以导出其他包.但是,在编译时'com.bundleB'现在可以从测试片段中的'com.bundleA.foo'访问类!这是不希望的,因为片段不会被部署,因此会出现运行时错误.

在这种情况下,最佳做法是什么?

小智 0

问题在于您的用例:您希望 com.bundleB.tests 导入 com.bundleA.utils,但 com.bundleA.utils 是 com.bundleA 的片段。为单元测试创​​建片段是可以的,但当此片段的某些部分必须由其他包中的其他单元测试使用时,就不行了。您应该创建一个仅包含必须共享的 utils 类 (com.bundleC) 的包,该类仅由unittest 片段使用并且包含 com.bundleA.utils 包。