Git Product home page Git Product logo

example-csharp's Introduction

Codecov C# Example

https://codecov.io @codecov [email protected]

AppVeyor codecov

Solution

Start by restoring the nuget packages and building the solution.

Generate the Coverage File

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.

xUnit

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:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml"

Then a coverage report will be generated.

MSTest

Execute the following in your solution's root,

OpenCover.Console.exe -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" -targetargs:"/testcontainer:"".\MyUnitTests\bin\Debug\MyUnitTests.dll" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml"

where you may need to change the -target flag to point to the correct version of MSTest.

Uploading Report

Many options exit for uploading reports to Codecov. Three commonly used uploaders for .NET are

  1. Codecov-exe (C# source code)
  2. Bash
  3. 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.

Codecov-exe

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 "MyProject_coverage.xml" -t <your upload token>

the report will be uploaded.

Bash

In bash run the following to upload the report

curl -s https://codecov.io/bash > codecov
chmod +x codecov
./codecov -f "MyProject_coverage.xml" -t <your upload token>

Python

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 "MyProject_coverage.xml" -t <your upload token>

Continous Integration

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

Codecov-exe using Chocolatey

image: Visual Studio 2015

before_build:
- nuget restore
- choco install opencover.portable
- choco install codecov

build:
  project: CodecovProject.sln
  verbosity: minimal

test_script:
- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml"
- codecov -f "MyProject_coverage.xml"

Codecov-exe using NuGet

Using this method you can cache your packages.config file.

image: Visual Studio 2015

before_build:
- nuget restore

build:
  project: CodecovProject.sln
  verbosity: minimal

test_script:
- .\packages\<ADD PATH>\OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml"
- .\packages\<ADD PATH>\codecov.exe -f "MyProject_coverage.xml"

Python

image: Visual Studio 2015

before_build:
- nuget restore
- choco install opencover.portable

build:
  project: CodecovProject.sln
  verbosity: minimal

test_script:
- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml"
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
- pip install codecov
- codecov -f "MyProject_coverage.xml"

Cake.Codecov

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. It makes using OpenCover and Codecov-exe really easy!

Sample Project

An example C# project using AppVeyor, xUnit, OpenCover, and Codecov-exe is DotNetAnalyzers/StyleCopAnalyzers.

example-csharp's People

Contributors

ddur avatar freelancingmikey avatar jericho avatar joaoasrosa avatar larzw avatar stevepeak avatar uuf6429 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.