繁体   English   中英

创建自定义测试容器模块?

[英]Create custom testcontainer modules?

提示:本站为国内最大中英文翻译问答网站,提供中英文对照查看,鼠标放在中文字句上可显示英文原文

我正在使用 JUnit5 + 测试容器。

我看到有这样的 Testcontainer 模块: https://github.com/testcontainers/testcontainers-java/tree/main/modules

我想构建自己的 Testcontainers 自定义模块。

有没有办法让开发人员构建自己的?

是的,您可以扩展GenericContainer class。通过重写containerIsStarted等方法或添加您自己的方法,您可以自定义容器的行为。

看看这些模块是如何实现的,例如 MongoDB 一个 它覆盖containerIsStarted以初始化副本集:

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) {
    if (reused && isReplicationSetAlreadyInitialized()) {
        log.debug("Replica set already initialized.");
    } else {
        initReplicaSet();
    }
}
问题未解决?试试搜索: 创建自定义测试容器模块?
暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2023 STACKOOM.COM