在GitHub拉取请求上显示C#代码覆盖率?

时间:2016-10-10 02:07:48

标签: c# github continuous-integration travis-ci pull-request

我们正在使用C#6.0项目,并使用Gi​​tub进行版本控制。我们还使用Travis构建并使用它来检查拉取请求。

有没有办法让Travis(或其他一些服务)计算我们的代码覆盖率并在拉取请求中显示该值?

1 个答案:

答案 0 :(得分:2)

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.