How I added AppVeyor, Codecov to .Net Core Open Source Project
AppVeyor is Continous Integration and Deployment solution where you can build, test and deploy your apps faster to any platform. One good advantage of using appveyor is that it is free for Open Source repositories. It's actually good when your repo is accepting pull request from people and then you can test if the pull request is merging or not.
On the other hand, Codec helps you to do a health check on your code, i.e. it is a measurement on how many lines of your code are executed when automated tests are performing. Now 100% Code Coverage means that all your code is covered under tests, but that is very hard to achieve.
I have to do a lot of commits to test the AppVeyor and Codecov and at last, it iwas successful and I can build and generate a code coverage report for my application. At first, I have started using NuGet package OpenCover to create code-coverage in my local environment and it was working after trial and error method.
The Script I have used is as below
OpenCover.Console.exe -register:user
-target:"C:\Program Files\dotnet\dotnet.exe"
-targetargs:"test\LetsDisc.Tests\bin\Debug\netcoreapp2.1\LetsDisc.Tests.dll -noshadow"
-oldStyle -output:".\coverage.xml"
-filter:"+[LetsDisc*]* -[Tests*]*" -coverbytest:"XUnit"
But as a developer, we should know that what works in local has a 100% probability that it will not work in some other environments. That is what happened in my case when I tried to run the above script in AppVeyor some or the other issues are popping up. But at last, I made it work. So the final script is
version: 1.0.{build}
image: Visual Studio 2017
configuration: Release
skip_tags: true
before_build:
- nuget restore
- nuget install OpenCover -OutputDirectory packages -Version 4.6.519
build_script:
- msbuild /verbosity:quiet LetsDisc.sln
test_script:
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe
-register:user
-target:"C:/Program Files/dotnet/dotnet.exe"
-targetargs:"test --logger:trx;LogFileName=results.trx
/p:DebugType=full
C:\projects\letsdisc\test\LetsDisc.Tests\LetsDisc.Tests.csproj"
-output:"coverage.xml" -filter:"+[LetsDisc*]* -[Tests*]*"
after_test:
- ps: |
$env:PATH = 'C:\msys64\usr\bin;' + $env:PATH
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
bash codecov.sh -f "coverage.xml"
The above script means on every build I will be updating it with a version of 1.0.{buildNumber}, then use Visual Studio 2017 as an image to build the project, then use configuration as release mode and not debug so that it can be easily deployable. Before the build just restoring all the nuget package, as well as installing OpenCover specific version which works with AppVeyor. After that building the project using msbuild and then running my test script to run the tests and create the coverage report. After the test is scuccessful deploying the coverage.xml file to the Codecov website.
It was fun as well as a learning experiment where I learned to use an Appveyor app as well adding the Coverage report to my project.
Repo : https://github.com/codingdefined/LetsDisc