2

我想在每次测试执行之前启动一个新的 postgres docker 容器,而不是在运行所有集成测试之前启动一次。我目前拥有的配置就像大多数谷歌结果一样:

     <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.33.0</version>
                <configuration>
                    <imagePullPolicy>IfNotPresent</imagePullPolicy>
                    <images>
                        <image>
                            <alias>it-database</alias>
                            <name>postgres:11.3</name>
                            <run>
                                <namingStrategy>alias</namingStrategy>
                                <ports>
                                    <port>5555:5432</port>
                                </ports>
                                <wait>
                                    <log>(?s)database system is ready to accept connections.*database system is ready to accept connections
                                    </log>
                                    <time>20000</time>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>docker:start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker:stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
4

1 回答 1

1

我强烈建议深入研究Testcontainers,因为 testcontainers 可以在集成测试中完全按照您的喜好进行操作。

于 2020-09-01T19:44:04.243 回答