简体   繁体   English

在Maven的Docker内部运行单一集成测试

[英]Running single integration test inside docker in maven

I am trying to run integration testing on my maven project inside a docker container. 我正在尝试在Docker容器中的Maven项目上运行集成测试。 I am using dockerfile-maven plugin to move jar file inside my docker container and maven-failsafe-plugin to initiate my integration testing. 我正在使用dockerfile-maven插件在我的docker容器内移动jar文件,并使用maven-failsafe-plugin启动集成测试。 But somehow integration testing starts before docker being built. 但是以某种方式,集成测试在构建docker之前就开始了。 Also it doesn't call my test functions. 而且它不调用我的测试函数。

Here is my pom.xml snippet. 这是我的pom.xml代码段。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                <goals>
                    <goal>integration-test</goal>
                </goals>
                <configuration>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <version>1.3.7</version>
            <executions>
                <execution>
                    <id>default</id>
                    <goals>
                        <goal>build</goal>
                        <goal>push</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <repository>rohitbarnwal7/presto_him</repository>
                <tag>${project.version}</tag>
                <buildArgs>
                    <JAR_FILE>plugin-${project.version}-jar-with-dependencies.jar</JAR_FILE>
                </buildArgs>
            </configuration>
        </plugin>

Update: With above configuration, integration test class are being called but none of the test is actually executed. 更新:通过以上配置,正在调用集成测试类,但实际上未执行任何测试。

Any help will be highly appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。

You need to bind the building of the image to a maven phase that runs before integration test. 您需要将映像的构建绑定到在集成测试之前运行的Maven阶段。

As documented in Bind Docker commands to Maven phases , you can bind building the docker image to a specific maven phase as such: 如将Docker命令绑定到Maven阶段中所述 ,您可以将构建Docker映像绑定到特定的Maven阶段,如下所示:

build-image compile package 构建映像编译包

In this case, building the image will take place at the maven package phase which will run before integration-test phase 在这种情况下,构建映像将在Maven package阶段进行,该阶段将在integration-test阶段之前运行

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

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