jacobvoller.com
jacobvoller.com

Reputation: 516

Show C# code coverage on GitHub pull requests?

We are using have a C# 6.0 project, and using Gitub for version control. We also use Travis to build and use it as a check for the pull requests.

Is there a way to get Travis (or some other service) to calculate our code coverage and get that value displayed on the pull requests?

Upvotes: 4

Views: 1348

Answers (1)

Bruno Garcia
Bruno Garcia

Reputation: 6408

I've just added to Greentube.Monitoring Github repository through this Pull request

There are multiple options for tools but I'll describe the setup I've come up with:

I'm using Travis-CI and AppVeyor for CI but since OpenCover doesn't work on Linux or MacOS, I could only generate cover data from AppVeyor.

One thing to note is that OpenCover currently doesn't support portable pdbs, which is the default for .NET Core projects. For that reason I created a project configuration called Coverage where I have full pdbs.

Once you get coverage report generated correctly locally, you can create an account on Codecov and link your repository. You'll need to send the first report to see anything there.

I wrote a script so I can see/tune the coverage report locally before sending the coverage over to codecov. Take into account that there are many other options if for some reason you don't want to use codecov.

Either locally or on AppVeyor, you need to specify the Codecov Token in order to upload the coverage data. You can use that by passing an argument to the CLI tool or setting the environment variable CODECOV_TOKEN. AppVeyor has an Environment section where you can define that (that's why you won't find any token hard-coded in my script).

Finally, I've added codecov.yml with project status which enables Github Status integration.

Upvotes: 3

Related Questions