我正在使用 Pax Exam 4.8、junit4、JBoss Fuse 作为 OSGi 容器为一些 OSGi 包开发集成测试。假设标准 Maven 设置。
容器启动,我的包已部署并正确启动。
现在在我的测试代码中,我需要加载资源并将其内容写入文件。如果我理解正确,单元测试会自动部署为测试探针包。
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class ExampleTest {
@javax.inject.Inject
BundleContext bundleContext;
@Configuration
public Option[] config() throws Exception {
// container setup
}
@Test
public void testThatApplicationProcessesThisFile() {
InputStream is1 = getClass().getResourceAsStream("myResource"); // returns null
Bundle probeBundle = bundleContext.getBundle("local");
InputStream is2 = probeBundle.getResource("myResource").openStream();
// getResource() returns null
// write the resource as a file
}
}
如何在 Pax Exam 测试中加载资源?如何检查资源是否包含在测试探针包中?