目前,我有用于使用Pax-Exam 5测试内部类的测试类。
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader("Fragment-Host", "com.mycompany.abc");
return probe;
}
我使用Fragment-Host的原因是避免为包com.mycompany.abc导出内部包。 但是我得到这个错误
org.ops4j.pax.exam.TestContainerException: org.osgi.framework.BundleException: Invalid operation on a fragment.
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.install(NativeTestContainer.java:135)
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.install(NativeTestContainer.java:140)
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.installProbe(NativeTestContainer.java:428)
at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.setUp(EagerSingleStagedReactor.java:68)
at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.beforeClass(EagerSingleStagedReactor.java:106)
at org.ops4j.pax.exam.spi.reactors.ReactorManager.beforeClass(ReactorManager.java:400)
at org.ops4j.pax.exam.junit.DriverExtension.beforeClassBlock(DriverExtension.java:130)
at org.ops4j.pax.exam.junit.ExtensibleRunner$1.evaluate(ExtensibleRunner.java:53)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.ops4j.pax.exam.junit.PaxExam.run(PaxExam.java:78)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: org.osgi.framework.BundleException: Invalid operation on a fragment.
at org.eclipse.osgi.container.Module.checkFragment(Module.java:520)
at org.eclipse.osgi.container.Module.start(Module.java:408)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:447)
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.install(NativeTestContainer.java:131)
... 15 more
还有其他解决方法吗?
谢谢
答案 0 :(得分:0)
Pax考试支持分片的预配,因为您可以在预配选项上调用.noStart()
来告诉Pax考试不得开始捆绑/片段:
CoreOptions.mavenBundle("gid", "aid", "version").noStart();
但是您要达到的目标是不同的,您正在尝试将探针包变成测试包的一部分。
您仍然可以实现您的目标,而不必按如下方式将探针片段化:
有关示例,请参见以下类:
换句话说,不是使探针成为宿主的片段,而是动态创建一个空片段,只是为了使探针受益而导出宿主的软件包。
免责声明:我没有尝试过,这只是一个假设。