构建 Docker 镜像并运行测试
现在 。目录是您的项目,它以根 POM 开头。
(包括 . 在下一行的末尾)
$ sudo docker build --no-cache -t my-image:1 -f ./Dockerfile . $ sudo docker run -it --rm my-image:1 /bin/sh
在 docker 的 shell 控制台中运行命令 mvn test。
当前目录中的 Dockerfile
FROM maven:3.5.3-jdk-8-alpine COPY ./. /
考试
当前目录中的位置。
src/test/java/MyTest.java
简单测试等待 3 秒:
import org.junit.Test;
public class MyTest {
@Test
public void test() throws InterruptedException {
Thread.sleep(3000L);
}
}
聚甲醛
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>x</groupId>
<artifactId>y</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>latest plugin version here</version>
</plugin>
</plugins>
</build>
</project>



