如何在 bnd 中使用测试容器

问题描述

我是 bndtools 的新手。我想使用 testcontainers (https://www.testcontainers.org/) 来测试一个应该连接到 MQTT 代理的 osgi 包。所以我可以测试连接、连接丢失等策略。 我不明白 maven 和 bnd 存储库是如何协同工作的,所以在我明白之前,我不使用 maven。然后我尝试通过将它添加到 build.bnd 来“导入”测试容器:

-plugin.6.junit: \
    aQute.bnd.repository.maven.pom.provider.BndPomRepository; \
        releaseUrl=https://repo.maven.apache.org/maven2/; \
        readOnly=true; \
        name="Maven Central JUNIT";\
        revision="org.osgi:org.osgi.test.junit5:0.10.0,\
        org.osgi:org.osgi.test.junit4:0.10.0",\
        org.testcontainers:testcontainers:1.15.2

但是 bnd 说“无法加载插件 org.testcontainers:testcontainers:1.15.2。” 我迷路了...

解决方法

您使用的语法错误...'revision' 参数采用带引号的字符串。该字符串以 junit4:0.10.0",\ 结尾。在带引号的字符串关闭后添加测试容器参数。所以以下应该有效:

-plugin.6.junit: \
    aQute.bnd.repository.maven.pom.provider.BndPomRepository; \
        releaseUrl=https://repo.maven.apache.org/maven2/; \
        readOnly=true; \
        name="Maven Central JUNIT";\
        revision="org.osgi:org.osgi.test.junit5:0.10.0,\
            org.osgi:org.osgi.test.junit4:0.10.0,\
            org.testcontainers:testcontainers:1.15.2"

Maven Bnd Repository 更易于使用,因为它允许您在文本文件中指定 GAV,每行一个。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...