Step 7c: Add the Codecov Nuget to the test project
Add the most recent version from codecov as a NuGet into your test project:
dotnet add package Codecov --version 1.1.0
Step 8: Configure the Azure Pipeline file to upload the test results
When the .NET Core 2.1 unit-test project is tested, the code coverage should be generated and formatted in opencover format.
For this the NuGet package Coverlet should be added to the test project. In addition the command to execute the test should contain these three parameters:
- –logger trx
The full command looks like:
# Build source, tests and run tests with coverage
- script: |
dotnet test ./test/MyTestProject.csproj -c Debug --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
displayName: 'Build source, tests and run tests with coverage'
Note the only way to correctly execute the codecov.exe application, is to reference this with using the full path where the NuGet is installed.
# Upload coverage to codecov.io
- script: |
%USERPROFILE%\.nuget\packages\codecov\1.1.0\tools\codecov.exe -f "./test/MyTestProject/coverage.opencover.xml" -t $(CODECOV_TOKEN)
displayName: Upload coverage to codecov.io
Step 9: View the code coverage for Pull Request in GitHub
When all is configured correctly in the GitHub project, the Pull Request should include codecov statistics like this:
Full Solution (YML)
The full YML file looks like this.
For the project and real YML file, see the WireMock.Net project.