Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有Eclipse扩展API的OSGi测试片段依赖项_Java_Dependencies_Osgi_Eclipse Rcp - Fatal编程技术网

Java 具有Eclipse扩展API的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.

如果我理解正确,建议在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.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”访问类了!这是不需要的,因为不会部署片段,因此会出现运行时错误


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

问题在于您的用例:您希望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”作为一个片段将重新建立从生产代码中访问测试软件的问题。