1

SonarQube is a great tool to see the code coverage on new code. Let assume we're working on a project which has the legacy code. (Unit tests were done with C# and NUnit)

How can the developers determine how many percentage of the code coverage on new code from the development machine. So that they can add enough unit tests sooner than receiving the report from the SonarQube.

Here is an example: - Developers are writing code on their development machines, they are working on different code branches but should be ensure that the new code that they have added was covered 80% unit test (we don't care the legacy code but we care the new code) - SonarQube runs every single day along with the CI tool to analyze the code in the "Develop" branch and reproduces the code coverage on new code (in the report). But developers can't see that information until the CI gets run. - We want some tools (or solution), so that developers can see the code coverage on new code directly in Visual Studio, or at least from the development machine, so they will know that they didn't have enough unit tests for the code that they have written, they must add more unit tests before checking the code to the source control.

Phuc
  • 479
  • 2
  • 4
  • 15
  • Not sure what the question is - can developers run SonarQube? probably... Are there other tools to measure coverage in C#? sure, e.g. NCover... What is the problem you're trying to solve? other than the trivial answer: have developers run code coverage on their machine... – Amittai Shapira Apr 17 '17 at 14:55
  • I've updated the question by giving an example, could you please help? thanks – Phuc Apr 18 '17 at 08:47

1 Answers1

0

There are many code coverage tools for C# that developers can run from their desktop on their branch, see some tools here. In my team we've had the coverage run on server (we've used NCover) and developers were able to access coverage details via the web.
As you've mentioned the easiest way is to use Visual Studio built-in code coverage but this is available only for the Enterprise Version.
Other option would be to use a coverage tool that has VS plugin, e.g. NCover, dotCover or OpenCover.
There are few points to notice here:
1. Coverage results may differ between tools, as there are multiple metrics and techniques to measure them.
2. Code coverage is far from perfect technique to measure the quality of developers testing. I'd want developers to focus on developing the best code they can and the best tests to verify their code works, and not to worry about artificial numbers such as 80% code coverage that may say nothing on quality. Code coverage tools can be helpful to identify ways to improve existing tests and things like dead code, but should be used with caution.

To summarize: it's possible to run code coverage from each developer's desktop but it seems to me counter productive to have developers focusing on coverage numbers and put less focus on developing quality code and tests.

Community
  • 1
  • 1
Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
  • Thank you for very helpful answer. I know that code coverage is the silver-bullet to measure the code quality. Developers should keep in their mind that writing good code and good tests are key of software quality. However, working with a big team or a process for the whole company is not easy, we are using the SonarQube to analyse the code quality and send the reports to developers. Besides, our projects have big amount of legacy code, that why we care "Code Quality On New Code" – Phuc Apr 19 '17 at 02:13
  • I'm happy that my answer was helpful :-) I've added some info on what my team was actually doing (it was few years ago) on coverage without running a tool on each developer (some did - myself included) machine, and usually we were able to get high coverage numbers. – Amittai Shapira Apr 20 '17 at 02:32
  • I also highly recommend Brian Marick's article (I;ve also put this link in my answer) to better understand how to use coverage efficiently - http://www.exampler.com/testing-com/writings/coverage.pdf – Amittai Shapira Apr 20 '17 at 02:35