gilab 展示测试用例结果详情页面


 

Python
此示例使用带有 --junitxml=report.xml 标志的 pytest 将输出格式化为 JUnit 报告 XML 格式gitlab 会自动去解析report.xml 这个文件,并且将每个case的测试结果展示在gitlab中

pytest:
  stage: test
  script:
    - pytest --junitxml=report.xml
  artifacts:
    when: always
    reports:
      junit: report.xml

pytest.ini

[pytest]
;addopts = -s
;addopts = -s --capture=no
;addopts = -s --html=./report/report.html
;addopts =  -s  --alluredir allure-results
addopts =  -s  --alluredir report1 --junitxml=report.xml
;addopts =  -s --encoding=utf-8
;log_cli=0
;allure generate ./report1 -o ./report1/html/ --clean  生成html报告
testpaths = ./testcases
;python_files = test_*reg.py
;python_files = test_*ved.py
;python_files = test_*reg.py  *search.py
;python_files = *app.py
;python_files = *search.py *other.py  *temp01.py *temp02.py
python_files =  *test_wea*
python_classed = Test_*
python_functions = test_*

stages:
    - build
    - test
    - deploy
build:
    stage: build
    tags:
        - build
    script:
        - echo $USER
        - echo "build"
test:
    stage: test
    tags:
        - build
    script:
        - echo $USER
        - echo "test"
        - python3 -m pytest
#        - python3 ./page/weather.py
#        - python3 ./page/welab_app.py
#        - python3 ./page/find_ele_by_more.py
    artifacts:
        when: always
        reports:
            junit: report.xml
#    artifacts:
#        when: always
#        paths:
#            - target1/
#            - TestReport/
#        expire_in: 1 week
#        reports:
#            junit: target1/surefire-reports/TEST-TestSuite.xml


#pytest -- mac安装了pytest,但是输入pytest却提示命令不存在
#解决办法:
#在当前环境输入pytest,使用的是Mac自带的python环境(2.7)
#如果要使用python3,需要使用python3 -m pytest

deploy:
    stage: deploy
    tags:
        - build
    script:
        - echo $USER
        - echo "deploy2"


gilab 展示测试用例结果详情页面_第1张图片

点击Job test可以看到每个case的名字,即代码中每个方法的名字

gilab 展示测试用例结果详情页面_第2张图片

gilab 展示测试用例结果详情页面_第3张图片

 这个文字是官方文档介绍,非常详细

单元测试报告示例 | 极狐GitLab

学习文档

gitlab_ci.yml展示单元测试报告 (FREE)_gitlab集成单元测试-CSDN博客

你可能感兴趣的:(测试用例,log4j)