gitlab readme 测试覆盖率添加

阅读更多

第一步:添加一个子模块:contract-coverage,然后在这个空的模块里只要发一个pom.xml即可,内容如下:



    
        com.ivy.contract-management
        parent
        1.1-RELEASE
        ../
    
    4.0.0

    contract-coverage

    
        ../contract-master/target
        ../contract-element/target

        ../contract-master/target/classes
        ../contract-element/target/classes

        ../contract-master/src/main/java
        ../contract-element/src/main/java

        ../contract-master/target/generated-sources/annotations
        
        ../contract-element/target/generated-sources/annotations
        
    

    
        
            
                org.apache.maven.plugins
                maven-dependency-plugin
                
                    
                    
                        jacoco-dependency-ant
                        
                            copy
                        
                        process-test-resources
                        false
                        
                            
                                
                                    org.jacoco
                                    org.jacoco.ant
                                    ${jacoco.version}
                                
                            
                            true
                            ${basedir}/target/jacoco-jars
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-antrun-plugin
                1.8
                
                    
                        post-integration-test
                        
                            run
                        
                        
                            
                                
                                
                                
                                    
                                
                                
                                
                                    
                                        
                                            
                                        
                                        
                                            
                                        
                                    
                                    
                                        
                                            
                                                
                                                
                                            
                                            
                                                
                                                
                                            
                                        
                                    
                                    
                                    
                                    
                                
                            
                        
                    
                
                
                    
                        org.jacoco
                        org.jacoco.ant
                        ${jacoco.version}
                    
                
            
        
    


 

第二步: 在README.md里添加地址

     [![pipeline status](http://10.138.61.72/src/msa/contract-management/badges/develop/pipeline.svg)](http://10.138.61.72/src/msa/contract-management/commits/develop)

[![coverage report](http://10.138.61.72/src/msa/contract-management/badges/develop/coverage.svg)](http://10.138.61.72/src/msa/contract-management/commits/develop)

 

第四步:gitlab-ci.yml 里test stage里添加命令

unit-testing:
  stage: test
  tags: ["fund_04"]
  only:
    - master
    - ci
    - develop
  script:
    - mvn clean test
    - mvn clean verify
    - mvn clean verify -f contract-coverage/pom.xml
    - cat contract-coverage/target/coverage-report/html/index.html

 

第五步:在gitlab上,Settings -》CI/CD -》General pipelines settings 下 -》 Test coverage parsing 填上匹配规则: Total.*?([0-9]{1,3})%

 

第六步:

本地执行脚本就能跑出测试覆盖率报告

    - mvn clean test
    - mvn clean verify
    - mvn clean verify -f contract-coverage/pom.xml
    - cat contract-coverage/target/coverage-report/html/index.html

sit环境的话,合并代码时gitlab自动会跑,然后在readme.md 文件里就能看到测试覆盖率

 

你可能感兴趣的:(gitlab readme 测试覆盖率添加)