PartCover generates empty output xml file - nunit

I am using PartCover to produce code coverage report. I have used below command line,
"C:\Program Files (x86)\PartCover\PartCover .NET 4.0\PartCover.exe"
--target-work-dir Debug
--target "C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console-x86.exe"
--target-args "Test.dll /noshadow /xml=Reports\NUnitResults.xml"
--include [*Test*]*
--output Reports\Report.xml
Output xml file contains below lines only,
<?xml version="1.0"?>
<PartCoverReport date="2015-04-23T16:18:14.5723939-05:00" version="4.0"/>
I tried to uninstall PartCover and reinstall but did not work. (as pe link)
Any idea what the issue is ? Please show me right direction.
Here is console output,

Related

Azure pipeline - Convert .coverage to xml to generate code coverage report

I'm trying to generate a code coverage report using the build pipeline for the C# unit tests (MSTest2). Report can be generated using the Reportgenerator.exe but expects .xml file as the input. I have added the Visual Studio test task which has generated a .coverage file in the build artifact. We could use CodeCoverage.exe to convert .coverage to .xml file.
To test this locally, I have copied the .coverage file and on running:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code Coverage Tools\amd64>CodeCoverage collect /IIS /session:WebSession /output:'C:\CoverageFiles\test.coverage'
and
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code Coverage Tools\amd64>CodeCoverage analyze /output:'c:\CoverageFiles\results.xml' 'c:\CoverageFiles\test.coverage'
the script is not throwing any error and xml file is also not generated.
Is there any other way to generate the .xml file from .coverage file? Any help on this is appreciated.
You can use coverlet to create a coverage report in different format. Coverlet will be invoked by msbuild. You can check my azure-pipelines.yml, where I use coverlet in combination with reporgenerator to create the code coverage in the build pipeline.
Parts of the yml:
- script: |
echo $(Build.SourcesDirectory)
cd src\Mwd.Exceptions.Solution
mkdir $(Build.SourcesDirectory)\results
dotnet test --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
copy Mwd.Exceptions.Test\coverage.cobertura.xml $(Build.SourcesDirectory)\results
dotnet tool install dotnet-reportgenerator-globaltool --tool-path . --version 4.0.0-rc4
.\reportgenerator "-reports:$(Build.SourcesDirectory)\results\coverage.cobertura.xml" "-targetdir:$(Build.SourcesDirectory)\results" "-reporttypes:HTMLInline;HTMLChart"
dotnet test --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura creates the coverage in cobertura format, at the time the only format build pipelines are supporting.
.\reportgenerator "-reports:$(Build.SourcesDirectory)\results\coverage.cobertura.xml" "-targetdir:$(Build.SourcesDirectory)\results" "-reporttypes:HTMLInline;HTMLChart" generate the report.
Since coverlet adds build targets to msbuild, compiling your solution(s) via devenv.exe should also be supported.

How to store output of doctest in a junit xml format

How can the output generated from doctest in python be saved into a junit xml file?
Run the below command from the directory where the doctest file is placed
python -m pytest -v --junitxml=./.xml

OpenCover Can't find file location

I'm trying run a build args against open cover but I can't find the file location since there are spaces in the location itself
<executable>C:\Program Files (x86)\OpenCover\OpenCover.Console.exe</executable>
<buildArgs>-register:user -target:"C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe" -targetargs:"C:\Users\username\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll" /noshadow /xml=reports\TestResult.xml" - filter:"+[WebCrawlerMVC.Tests*]* -output:"C:\Program Files (x86)\CruiseControl.NET\server\reports\coverage.xml" </buildArgs>
</exec>
<exec>
<executable>C:\Program Files (x86)\ReportGenerator\bin\ReportGenerator.exe</executable>
<buildArgs>-reports:reports\coverage.xml</buildArgs>
the error comes out as File type not known: C:Users\username\Documents\Visual when i run it through the OpenCover console
so it's not being able to view the whole file path, is there a way around this? I realize my whole argument will have some errors still, but I can't get to fixing them until I resolve this one.
Update:
targetargs:"\"C:\Users\lardern\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll"
the "\ "C: seems to allow the spacing to go through, I still have errors with my code, but its no longer a file path issue.
Update2:
<task>
<exec>
<executable>C:\Program Files (x86)\OpenCover\OpenCover.Console.exe</executable>
<buildargs>-target:"C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe" -register:user -targetargs:"/nologo /noshadow \"C:\Users\username\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll" -filter:+[WebCrawlerMVC]* -output:coverage.xml </buildargs>
</exec>
</tasks>
this is this is the working version.
try escaping the quotes wrapping the path to the assembly
<buildArgs>-register:user -target:"C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe"
"-targetargs:\"C:\Users\username\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll\" /noshadow /xml=reports\TestResult.xml" - filter:"+[WebCrawlerMVC.Tests*]*" -output:"C:\Program Files (x86)\CruiseControl.NET\server\reports\coverage.xml" </buildArgs>
Maybe this link will provide a bit of help.
The environment variables are expanded before being passed to opencover and it looks like you have spaces in your path name. The Usage Wiki describes that arguments with spaces in them have to be escaped with \". I recommend you create a new variable with escaped paths for use with OpenCover.
Just a thought.

Gallio with NCover shows 0% code coverage in Sonar UI

I am using sonar-runner to run tests and code coverage over my C# code with the help of gallio plugin. The tests are running fine, but I am not able to see any code coverage on the sonar web UI.
My Sonar settings are as follows:
sonar-project.properties
mentioning only relevant bits
sonar.gallio.coverage.tool = NCover
sonar.NCover.installDirectory = C:/Program Files/NCover
sonar.donet.visualstudio.testProjectPattern = .Test
sonar.dotnet.buildConfigurations = "Release|x86"
Any idea what coule be missing??
sonar.projectKey=XXX:XXX
sonar.projectVersion=trunk
sonar.projectName=XXX
sources=.
sonar.language=cs
sonar.dotnet.visualstudio.solution.file=Project.sln
sonar.dotnet.excludeGeneratedCode=false
sonar.dotnet.4.0.sdk.directory=C:/WIndows/Microsoft.NET/Framework/v4.0.30319
sonar.dotnet.version=4.0
# Gallio
sonar.gallio.mode=
sonar.gallio.coverage.tool=NCover
sonar.gallio.runner=IsolatedAppDomain
sonar.NCover.installDirectory=c:/Program Files/NCover
sonar.gallio.installDirectory=C:/Program Files/Gallio
sonar.dotnet.test.assemblies=$(SolutionDir)/../**/bin/**/*.Tests.Unit.dll
# FXCop
sonar.fxcop.mode=
#StyleCop
sonar.stylecop.mode=
#NDeps
sonar.ndeps.mode=skip
sonar-runner.properties
You said
sonar.dotnet.buildConfigurations = "Release|x86"
If that's true, your build likely isn't generating .pdb files, which are needed to figure out the mapping between the binaries and your source files.
Does it work if you try it with a Debug build?
I was seeing this same behavior with NCover in Sonar. I found that Sonar was generating invalid arguments for Gallio's NCover runner.
Try piping the output from Sonar's runner into a text file so that you can examine the arguments more easily (on the command line, you can just type sonar-runner > output.txt to do this).
You will likely see a line like this in your output:
INFO .u.c.CommandExecutor - Executing command: C:\Program Files\Gallio\bin\Gallio.Echo.exe /r:Local /report-directory:E:\Reports\.sonar /report-name-format:gallio-report /report-type:Xml E:\Projects\UnitTests\bin\Release\UnitTests.dll /runner-property:NCoverCoverageFile=E:\Reports\.sonar\coverage-report.xml /runner-property:NCoverArguments=//ias MyFirstAssembly;MySecondtAssembly;MyThirdAssembly
If you attempt to execute this manually via Gallio on the command line, you will get an error:
Cannot find file 'MyFirstAssembly;MySecondtAssembly;MyThirdAssembly'
If you edit this list manually down to a single entry such as MyFirstAssembly*, everything will work as expected.
This seems to indicate that Sonar is generating invalid command line arguments for Gallio. As much as I love NCover, the easiest solution was to use OpenCover instead.

NUnit assembly not found

I've used NUnit before, but not in a while, and never on this machine. I unzipped version 2.4.8 under Program Files, and I keep getting this error when trying to load my tests.
Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified**
In order to simplify the problem, I've compiled the most basic possible test file.
using NUnit.Framework;
namespace test
{
[TestFixture]
public class Tester
{
[Test]
public void ATest()
{
Assert.IsTrue(false, "At least the test ran!");
}
}
}
I've added "C:\Program Files\NUnit-2.4.8-net-2.0\bin" to my PATH (and rebooted). Note that if I copy the test assembly into that folder, then
C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console test.dll
works, but
C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console c:\dev\nunit_test\test.dll
and
C:\dev\nunit_test>nunit_console test.dll
fail with the above error.
Presumably I could get around this by copying the NUnit.Framework DLL file into my project's bin folder, but I don't remember having to do this in the past. Moreover, I get the same error in the GUI. Shouldn't the GUI know where the framework is located (that is, in the same folder)?
I'm not using Visual Studio. I use the following line to compile the test project.
%windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /r:"C:\Program Files\NUnit-2.4.8-net-2.0\bin\nunit.framework.dll" /t:library /out:test.dll test.cs
I tried both the .msi and the .zip file with the same result.
Make sure you have added a reference to nunit.framework. If you have, then make sure the properties of that reference have the copy local property set to true.
I had the same problem, and I had installed using NUnit-2.4.8-net-2.0.msi. Expanding on the "add to the GAC" comment, here's what I did:
Open your "Visual Studio command prompt (generally: make sure gacutil is in your path) and: cd "C:\Program Files\NUnit 2.4.8\bin"
Unregister your NUnit entries from the GAC. You can do this by finding the NUnit entries registered in the GAC:
gacutil /l | find /i "nunit" > temp.bat && notepad temp.bat
Prepend the nunit.core and nunit.framework lines with "gacutil /uf", i.e.:
gacutil /uf nunit.core,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77
gacutil /uf nunit.framework,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77
Run your .bat file to remove them:
temp.bat
Register the NUnit DLL files you need:
gacutil /i nunit.core.dll
gacutil /i nunit.framework.dll
If you install using NUnit-2.4.8-net-2.0.msi, the NUnit assemblies are added to the GAC.
You can also reinstall manually by running gacutil from the Visual Studio 2005 command prompt.
Note that the current NUnit installation (2.5.10) doesn't register itself automatically in the GAC.
If you must use GAC, register it via gacutil /i <nunitframeworkpath> where nunitframeworkpath is usually %Program Files%\NUnit\net-2.0\framework\nunit-framework.
I got this error message today when I tried to add a new test assembly to an existing NUnit test project. It seems that my test projects had multiple path references to identical nunit.framework.dll assemblies.
If you have more than one test assembly in your NUnit project, you may want to verify the Path property of the nunit.framework reference in your test projects. Once I made them match, the error message went away.