【问题标题】:Junit report is not updated after run tests on gitlab在 gitlab 上运行测试后,Junit 报告未更新
【发布时间】:2020-12-06 14:03:21
【问题描述】:

我在gitlab cigitlab runner 上运行自动化测试,除报告外,一切正常。测试后junit 报告未更新,始终显示相同的通过和未通过测试,即使cmd 显示不同数量的通过测试。

Gitlab 脚本:

    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"

【问题讨论】:

  • 如果你在本地运行 JUnit 会发生什么,例如使用命令行还是IDE? JUnit 报告是否正确?如果不是,那么这个问题与gitlab/docker无关。另外,请提供 junit 报告的输出以及您的期望。

标签: docker junit gitlab dockerfile gitlab-ci


【解决方案1】:

在我的 gitlab 管道中使用 docker-in-docker 时,我遇到了类似的问题。您在容器内运行测试。因此,测试结果存储在您的“被测容器”中。但是,gitlab-ci 路径引用的不是“被测容器”,而是 docker-in-docker 环境的外部容器。

您可以尝试通过以下方式将测试结果从图像直接复制到外部容器:

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

所以,在你的情况下,这将是这样的(未经测试......!):

...

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

另外,有关docker cp 命令的详细说明,请参阅此帖子:https://stackoverflow.com/a/59055906/6603778

请记住,docker cp 需要您要从容器中复制的文件的绝对路径。

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 2022-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    相关资源
    最近更新 更多