skip to Main Content

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


  1. Chosen as BEST ANSWER

    I solved it by updating Junit from 4 to 5 Now everything works perfectly.


  2. 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 –

    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 Maven to download dependencies
    RUN mvn -f pom.xml dependency:go-offline
    
    # Build the application
    RUN mvn -f pom.xml clean package
    
    # Run tests (this is typically not necessary if you are building the project with 'mvn package')
    # RUN mvn -f pom.xml test
    
    CMD ["mvn", "test"]
    

    Please make sure your tests are located in standard Maven directory structure (src/test/java).

    I hope it works for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search