title: SonarQube Test Coverage with MsTest
body: <p>I have been trying to get <code>SonarQube</code> working with a simple dot net app. I have had some success getting it up and running but code coverage is not working.</p>
  
  <p>It looks like many other people have faced this issue when SonarQube discontinued support for many of the 'go to' coverage tool such as <code>DotCover and OpenCover</code> via <a href="http://jira.sonarsource.com/browse/SONARCS-37" rel="noreferrer">Gallio</a> </p>
  
  <blockquote>
    <p>Examples which I have followed are:</p>
    
    <ul>
    <li><p><a href="https://stackoverflow.com/questions/25059696/sonar-runner-errors-out-during-processing-of-coveragexml-file-produced-from-vis">Sonar Runner errors out during processing of .coveragexml file produced from Visual Studio&#39;s MSTest</a></p></li>
    <li><p><a href="https://stackoverflow.com/questions/29532519/vs2013-codecoverage-exe-runsettings-file-never-parses">VS2013 CodeCoverage.exe runsettings file never parses</a></p></li>
    </ul>
  </blockquote>
  
  <p>I have tried a few of the VS command line tools to generate a <code>.coverage</code> file</p>
  
  <pre><code>vstest.console.exe .\UnitTestProject1\bin\Debug\UnitTestProject1.dll /EnableCodeCoverage
  </code></pre>
  
  <p>and</p>
  
  <pre><code>CodeCoverage.exe collect /output:DynamicCodeCoverage.coverage .\UnitTestProject1\bin\Debug\UnitTestProject1.dll
  </code></pre>
  
  <p>And written some code like to covert it into a <code>.coveragexml</code> file from <a href="https://reportgenerator.codeplex.com/wikipage?title=Visual%20Studio%20Coverage%20Tools" rel="noreferrer">here</a></p>
  
  <p>To get the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0" standalone="yes"?&gt;
  &lt;CoverageDSPriv&gt;
    &lt;Module&gt;
      &lt;ModuleName&gt;unittestproject1.dll&lt;/ModuleName&gt;
      &lt;ImageSize&gt;32768&lt;/ImageSize&gt;
      &lt;ImageLinkTime&gt;0&lt;/ImageLinkTime&gt;
      &lt;LinesCovered&gt;12&lt;/LinesCovered&gt;
      &lt;LinesPartiallyCovered&gt;0&lt;/LinesPartiallyCovered&gt;
      &lt;LinesNotCovered&gt;0&lt;/LinesNotCovered&gt;
      &lt;BlocksCovered&gt;9&lt;/BlocksCovered&gt;
      &lt;BlocksNotCovered&gt;0&lt;/BlocksNotCovered&gt;
      &lt;NamespaceTable&gt;
        &lt;BlocksCovered&gt;9&lt;/BlocksCovered&gt;
        &lt;BlocksNotCovered&gt;0&lt;/BlocksNotCovered&gt;
        &lt;LinesCovered&gt;12&lt;/LinesCovered&gt;
        &lt;LinesNotCovered&gt;0&lt;/LinesNotCovered&gt;
  </code></pre>
  
  <p>And even used XSLT stylesheet provide in one that could be used by the SonarQube runner</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;results&gt;
    &lt;modules&gt;
      &lt;module name="unittestproject1.dll" path="unittestproject1.dll" block_coverage="100" line_coverage="100" blocks_covered="9" blocks_not_covered="0" lines_covered="12" lines_partially_covered="0" lines_not_covered="0"&gt;
        &lt;functions&gt;
          &lt;function name="Setup" type_name="UnitTest1" block_coverage="100" line_coverage="100" blocks_covered="1" blocks_not_covered="0" lines_covered="2" lines_partially_covered="0" lines_not_covered="0"&gt;
            &lt;ranges&gt;
              &lt;range source_id="1" covered="yes" start_line="13" start_column="9" end_line="13" end_column="10" /&gt;
              &lt;range source_id="1" covered="yes" start_line="15" start_column="9" end_line="15" end_column="10" /&gt;
            &lt;/ranges&gt;
          &lt;/function&gt;
  </code></pre>
  
  <blockquote>
    <p>when I run Sonar </p>
    
    <ol>
    <li>MSBuild.SonarQube.Runner.exe Begin</li>
    <li>MSBuild</li>
    <li>MSBuild.SonarQube.Runner.exe end</li>
    </ol>
    
    <p>I get errors like Caused By: <code>unknown XML Node</code>, Expect <strong>Coverage</strong> but
    got <strong>Results</strong></p>
  </blockquote>
  
  <p>This is because its does not like the structure of my XML, but I am not sure what is is expecting and how much work I have to do on the coverage file to convert it into a format that Sonar likes</p>
  
  <p>Hopefully I have been going down the wrong path and there is a simple way to integrate VS Coverage or <code>coveragexml</code> files into Sonar without too much work</p>
  
  <blockquote>
    <p>Extra Information on my <code>Sonar plugins</code> are</p>
    
    <ol>
    <li>c# = 4.1</li>
    <li>Generic Coverage = 1.1</li>
    </ol>
  </blockquote>