Spring Boot Junit单元测试未在docker镜像中运行

mnemlml8  于 2024-01-06  发布在  Spring
关注(0)|答案(2)|浏览(174)

我有一个spring Boot 应用程序,当我运行“mvn clean install”时,我的junit单元测试在IntelliJ中运行得很好,但是当我试图在docker镜像中运行它们时,它们实际上都没有运行,我得到的是它们被编译了,但是它们没有运行。

  1. FROM docker.xxxxx.com/oicp/standard/maven/amzn-maven-corretto8:latest AS build
  2. USER root
  3. ARG build
  4. LABEL build=${build}
  5. LABEL image=integration
  6. ARG appVersion=local
  7. COPY src /home/appuser/integration/src
  8. COPY pom.xml /home/appuser/integration/pom.xml
  9. COPY settings.xml /home/appuser/integration/settings.xml
  10. COPY entry.sh /home/appuser/integration/entry.sh
  11. WORKDIR /home/appuser/integration/
  12. RUN mvn -f pom.xml dependency:go-offline
  13. CMD mvn -f pom.xml clean package
  14. CMD mvn test-compile
  15. CMD mvn test
  1. Compiling 11 source files to /home/appuser/integration/target/classes
  2. [INFO]
  3. [INFO] --- resources:3.3.0:testResources (default-testResources) @ @@@@@ ---
  4. [INFO] Copying 0 resource
  5. [INFO]
  6. [INFO] --- compiler:2.5.1:testCompile (default-testCompile) @ @@@@@ ---
  7. [INFO] Compiling 2 source files to /home/appuser/integration/target/test-classes
  8. [INFO]
  1. -------------------------------------------------------
  2. [INFO] T E S T S
  3. [INFO] -------------------------------------------------------
  4. [INFO]
  5. [INFO] Results:
  6. [INFO]
  7. [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
  8. [INFO]
  9. [INFO] ------------------------------------------------------------------------
  10. [INFO] BUILD SUCCESS
  11. [INFO] ------------------------------------------------------------------------
  12. [INFO] Total time: 01:12 min
  13. [INFO] Finished at: 2023-12-05T17:47:29Z
  14. [INFO] -------------------------------------------------------------------
k2fxgqgv

k2fxgqgv1#

你在Dockerfile中有多个CMD语句,但是只有最后一个语句被执行,而不是你可以连接你的CMD命令。这里是更新的Dockerfile -

  1. FROM docker.xxxxx.com/oicp/standard/maven/amzn-maven-corretto8:latest AS build
  2. USER root
  3. ARG build
  4. LABEL build=${build}
  5. LABEL image=integration
  6. ARG appVersion=local
  7. COPY src /home/appuser/integration/src
  8. COPY pom.xml /home/appuser/integration/pom.xml
  9. COPY settings.xml /home/appuser/integration/settings.xml
  10. COPY entry.sh /home/appuser/integration/entry.sh
  11. WORKDIR /home/appuser/integration/
  12. # Run Maven to download dependencies
  13. RUN mvn -f pom.xml dependency:go-offline
  14. # Build the application
  15. RUN mvn -f pom.xml clean package
  16. # Run tests (this is typically not necessary if you are building the project with 'mvn package')
  17. # RUN mvn -f pom.xml test
  18. CMD ["mvn", "test"]

字符串
请确保您的测试位于标准Maven目录结构(src/test/java)中。
我希望它对你有用。

展开查看全部
px9o7tmv

px9o7tmv2#

我通过将Junit从4更新到5解决了这个问题,现在一切都完美地工作了。

相关问题