0

I run automated tests on gitlab ci with gitlab runner, all works good except reports. After tests junit reports are not updated, always show the same pass and not pass tests even thought cmd show different number of passed tests.

Gitlab script:

    stages:
      - build
      - test
    
    docker-build-master:
      image: docker:latest
      stage: build
      services:
        - docker:dind
      before_script:
        - docker login -u "xxx" -p "yyy" docker.io
      script:
        - docker build ./AutomaticTests --pull -t "dockerImage" 
        - docker image tag dockerImage xxx/dockerImage:0.0.1
        - docker push "xxx/dockerImage:0.0.1"
    
    test:
      image: docker:latest
      services:
        - docker:dind
      stage: test
      before_script:
        - docker login -u "xxx" -p "yyy" docker.io
      script: 
        - docker run "xxx/dockerImage:0.0.1"
      artifacts:
        when: always
        paths:
          - AutomaticTests/bin/Release/artifacts/test-result.xml
        reports:
          junit:
            - AutomaticTests/bin/Release/artifacts/test-result.xml

Dockerfile:

    FROM mcr.microsoft.com/dotnet/core/sdk:2.1
    
    COPY /publish  /AutomaticTests
    WORKDIR /AutomaticTests
    RUN apt-get update -y
    RUN apt install unzip
    RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
    RUN curl https://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip -o /usr/local/bin/chromedriver
    RUN unzip -o /usr/local/bin/chromedriver -d /AutomaticTests
    RUN chmod 777 /AutomaticTests
    
    CMD dotnet vstest /Parallel AutomaticTests.dll --TestAdapterPath:. --logger:"nunit;LogFilePath=..\artifacts\test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
DV82XL
  • 5,350
  • 5
  • 30
  • 59
  • What happens if you run `JUnit` locally, e.g. using command line or IDE? Is the JUnit report correct? If not, then this problem has nothing to do with gitlab/docker. Also, please provide the outputs of the junit report an what you are expecting. – DV82XL Aug 17 '20 at 13:09

1 Answers1

0

I had a similar issue when using docker-in-docker for my gitlab pipeline. You run your tests inside your container. Therefore, test results are stored inside your "container-under-test". However, the gitlab-ci paths reference not the "container-under-test", but the outside container of your docker-in-docker environment.

You could try to copy the test results from the image directly to your outside container via something like this:

mkdir reports
docker cp $(docker create --rm DOCKER_IMAGE):/ABSOLUTE/FILEPATH/IN/DOCKER/CONTAINER reports/.

So, this would be something like this in your case (untested...!):

...

    test:
      image: docker:latest
      services:
        - docker:dind
      stage: test
      before_script:
        - docker login -u "xxx" -p "yyy" docker.io
      script: 
        - mkdir reports
        - docker cp $(docker create --rm xxx/dockerImage:0.0.1):/AutomaticTests/bin/Release/artifacts/test-result.xml reports/.
      artifacts:
        when: always
        reports:
          junit:
            - reports/test-result.xml
...

Also, see this post for furhter explanation on the docker cp command: https://stackoverflow.com/a/59055906/6603778

Keep in mind, that docker cp requires an absolute path to the file you want to copy from your container.

micc
  • 1
  • 2