我有一个spring Boot 应用程序,当我运行“mvn clean install”时,我的junit单元测试在IntelliJ中运行得很好,但是当我试图在docker镜像中运行它们时,它们实际上都没有运行,我得到的是它们被编译了,但是它们没有运行。
FROM docker.xxxxx.com/oicp/standard/maven/amzn-maven-corretto8:latest AS build
USER root
ARG build
LABEL build=${build}
LABEL image=integration
ARG appVersion=local
COPY src /home/appuser/integration/src
COPY pom.xml /home/appuser/integration/pom.xml
COPY settings.xml /home/appuser/integration/settings.xml
COPY entry.sh /home/appuser/integration/entry.sh
WORKDIR /home/appuser/integration/
RUN mvn -f pom.xml dependency:go-offline
CMD mvn -f pom.xml clean package
CMD mvn test-compile
CMD mvn test
Compiling 11 source files to /home/appuser/integration/target/classes
[INFO]
[INFO] --- resources:3.3.0:testResources (default-testResources) @ @@@@@ ---
[INFO] Copying 0 resource
[INFO]
[INFO] --- compiler:2.5.1:testCompile (default-testCompile) @ @@@@@ ---
[INFO] Compiling 2 source files to /home/appuser/integration/target/test-classes
[INFO]
-------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:12 min
[INFO] Finished at: 2023-12-05T17:47:29Z
[INFO] -------------------------------------------------------------------
2条答案
按热度按时间k2fxgqgv1#
你在Dockerfile中有多个CMD语句,但是只有最后一个语句被执行,而不是你可以连接你的CMD命令。这里是更新的Dockerfile -
字符串
请确保您的测试位于标准Maven目录结构
(src/test/java)
中。我希望它对你有用。
px9o7tmv2#
我通过将Junit从4更新到5解决了这个问题,现在一切都完美地工作了。