https://codecov.io | @codecov | hello@codecov.io |
---|
Start by restoring the nuget packages and building the solution.
Coverage is generated using OpenCover. You can obtain it from NuGet or Chocolatey. If we run the following command in PowerShell to install OpenCover via Chocolatey,
choco install opencover.portable
the OpenCover commandline will become available.
Generation of coverage report is slighly different depending on the .NET platform of your test projects.
First install the xUnit console runner via Nuget or Chocolatey. If we run the following in PowerShell to install xUnit via Chocolatey
choco install xunit
and execute the following in your solution's root,
OpenCover.Console.exe -register:user -target:"xunit.console.x86.exe" -targetargs:".\test\CodecovExample.Tests\bin\Debug\CodecovExample.Tests.dll -noshadow" -filter:"+[CodecovExample.TargetProject*]* -[CodecovExample.Tests*]*" -output:".\CodecovExample-FSharp.xml"
Then a coverage report will be generated.
Many options exit for uploading reports to Codecov. Three commonly used uploaders for .NET are
- Codecov-exe (C# source code)
- Bash
- Python
For OS X and Linux builds, the recommended uploader is bash. For windows builds, all three uploaders work, but Codecov-exe does not require any dependencies. For example, the bash uploader and python uploader would require bash or python to be installed. This may or may not be an option.
First install Codecov-exe via Nuget or Chocolatey. If we run the following in PowerShell to install it via Chocolatey
choco install codecov
and then run the following in PowerShell
.\codecov -f "CodecovExample-FSharp.xml" -t <your upload token>
the report will be uploaded.
In bash run the following to upload the report
curl -s https://codecov.io/bash > codecov
chmod +x codecov
./codecov -f "CodecovExample-FSharp.xml" -t <your upload token>
First installed python (if you don't have it already). A simple way to install python is Chocolatey
choco install python
Next run the following in PowerShell
pip install codecov
.\codecov -f "CodecovExample-FSharp.xml" -t <your upload token>
The previous examples assumed local development. More commonly, you'll use a CI service like AppVeyor or TeamCity. For TeamCity builds please see the documentation. For AppVeyor builds using xUnit, your yaml file would look something like
image: Visual Studio 2017
before_build:
- nuget restore
- choco install opencover.portable
- choco install codecov
build:
project: CodecovExample.sln
verbosity: minimal
test_script:
- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\test\CodecovExample.Tests\bin\Debug\CodecovExample.Tests.dll -noshadow" -filter:"+[CodecovExample.TargetProject*]* -[CodecovExample.Tests*]*" -output:".\CodecovExample-FSharp.xml"
- codecov -f "CodecovExample-FSharp.xml"
Using this method you can cache your packages.config file.
image: Visual Studio 2017
before_build:
- nuget restore
build:
project: CodecovExample.sln
verbosity: minimal
test_script:
- .\packages\<ADD PATH>\OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\test\CodecovExample.Tests\bin\Debug\CodecovExample.Tests.dll -noshadow" -filter:"+[CodecovExample.TargetProject*]* -[CodecovExample.Tests*]*" -output:".\CodecovExample-FSharp.xml"
- .\packages\<ADD PATH>\codecov.exe -f "CodecovExample-FSharp.xml"
image: Visual Studio 2017
before_build:
- nuget restore
- choco install opencover.portable
build:
project: CodecovExample.sln
verbosity: minimal
test_script:
- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\test\CodecovExample.Tests\bin\Debug\CodecovExample.Tests.dll -noshadow" -filter:"+[CodecovExample.TargetProject*]* -[CodecovExample.Tests*]*" -output:".\CodecovExample-FSharp.xml"
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
- pip install codecov
- codecov -f "CodecovExample-FSharp.xml"
If you use Fake (F# Make) for your build automation there is a support for OpenCover.
If you use Cake (C# Make) for your build automation, there is a Cake.Codecov addin available. Cake also has built in support for OpenCover.
We are happy to help if you have any questions. Please contact email our Support at support@codecov.io