I have a spring boot application, my junit unit tests run perfectly in IntelliJ when I run "mvn clean install", but when try to run them inside of a docker image, non of them actually run, I get that they are compiled, but they don’t run.
here is the content of my docker-image:
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
Answers
I solved it by updating Junit from 4 to 5 Now everything works perfectly.
You’re having multiple CMD statements in your Dockerfile, however only last is getting executed instead this you can concatenate your CMD commands. Here is updated Dockerfile –
Please make sure your tests are located in standard Maven directory structure
(src/test/java)
.I hope it works for you.