zoukankan      html  css  js  c++  java
  • DotNetCore + Sonar + Coverlet 代码覆盖率检查

    一,下载 sonar-scanner-msbuild

    我当前下载的最新版本是:sonar-scanner-msbuild-4.5.0.1761-netcoreapp2.0

    https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild

    二,新建dotnetCore 项目 SonarDemo并创建SonarDemo.Tests Project

    三,解压sonar-scanner-msbuild-4.5.0.1761-netcoreapp2.0 至我们新建的dotnetCore项目

    进入sonar-scanner-netcore 编辑 SonarQube.Analysis.xml 设置SonarQube 地址。

    进入sonar-scanner-netcoresonar-scanner-3.2.0.1227conf 设置SonarQube 地址。

    四,SonarDemo.Tests 项目添加coverlet.msbuild

     

    五,编写单元测试

        public class UnitTests
        {
            [Fact]
            public void Test1()
            {
                var demoStr = new Demo();
    
                  var result=  demoStr.stringFormat("test");
    
                Assert.Equal("TEST", result);
            }
        }

    六,创建SonarScanner.MSBuild.bat

    dotnet test SonarDemo.Tests/SonarDemo.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[xunit.runner.*]*,[SonarDemo.Tests]*"
    
    dotnet sonar-scanner-netcoreSonarScanner.MSBuild.dll begin /k:SonarDemo /n:SonarDemo /v:1.0 /d:sonar.host.url=http://localhost:9000 /d:sonar.login=admin /d:sonar.password=admin /d:sonar.cs.opencover.reportsPaths=SonarDemo.Tests/coverage.opencover.xml /d:sonar.coverage.exclusions=[**Tests*.cs,coverage.opencover.xml]
    
    dotnet build
    
    dotnet sonar-scanner-netcoreSonarScanner.MSBuild.dll end /d:sonar.login=admin /d:sonar.password=admin

    七,编译通过后,双击SonarScanner.MSBuild.bat

    demo下载

  • 相关阅读:
    判断是否是唯一索引异常
    Sign in with Apple java
    spring 集成钉钉机器人
    list一个字段去重
    Math_Linear_algebra_05_正定矩阵
    Math_Linear_algebra_02_矩阵与线性方程
    Math_Calculus_04_多变量微积分
    Math_Linear_algebra_01_向量空间
    Linux_Best Practice_04_Ubuntu 18.04
    PMP_Previw
  • 原文地址:https://www.cnblogs.com/mnps/p/10179673.html
Copyright © 2011-2022 走看看