I am using Visual Studio Enterprise 2017 to develop my .net core projects.
My solution also has some unit test projects and I want to view my current Code coverage.
When I clicked Test -> Analyze Code Coverage -> All tests. All my unit tests ran but in Code Coverage Results it only reported code coverage for my unit test projects which doesn't make any sense to me.
Question 1: Do you guys experience the same issue with me? Any solution for this? I also need to set up build definition in VSTS to report code coverage.
Question 2: Also when I right clicked to debug 1 of my unit test. It executes ALL of my unit tests. Is this a bug in VS2017?
Update1: I found this topic: https://github.com/Microsoft/vstest/issues/597
Even with the "fixed" version I had issues (Only able to see code coverage for the test projects, not the actual projects I was testing). To workaround the problem I removed the <DebugType>Full</DebugType> from the test project.
So, as a summary:
Add package Microsoft.CodeCoverage (1.0.3) into your test project.
Add the <DebugType>Full</DebugType> tag on the .csproj file on
the projects we want to see code coverage values (inside <PropertyGroup> as explained on the vstest github link).
Run unit tests.
On the "Test Explorer" select passed unit tests, right click -> "Analyze Code Coverage for Selected Tests".
You should see code coverage for your assemblies.
My setup (Minimal setup?)
xunit (2.3.1)
xunit.runner.visualstudio (2.3.1)
Microsoft.NET.Test.Sdk (15.3.0)
Microsoft.CodeCoverage (1.0.3)
Visual Studio Enterprise 2017 (15.4.1)
You can try dotCover from Jetbrains. https://www.jetbrains.com/dotcover/features/
dotCover is a .NET unit testing and code coverage tool that works right in Visual Studio, helps you know to what extent your code is covered with unit tests, provides great ways to visualize code coverage, and is Continuous Integration ready. dotCover calculates and reports statement-level code coverage in applications targeting .NET Framework, Silverlight, and .NET Core.
It works fine with .NET Core & can show code coverage.
Supports multiple unit testing frameworks, namely MSTest, NUnit, xUnit (all out of the box) and MSpec (via a plug-in).
Based on this article (Code Coverage does not work in the IDE with netcoreapp1.x projects (VS 2017 RTM):
Code coverage is currently not implemented for netcore projects. The
work on this issue is in progress, it will come as part of post RTW
releases.
It looks like they are still working out the infrastructure (data collectors) bits before releasing. They are supposedly close.
https://github.com/Microsoft/vstest/issues/579
This issue has been fixed with Version 15.3:
https://github.com/Microsoft/vstest-docs/blob/master/docs/analyze.md#coverage
JDC's answer helped me to include my actual projects but I could not get rid of the test projects in the coverage report.
I managed it by adding a "CodeCoverage.runsettings" in my XUnit test project with the following content:
<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Exclude>
<ModulePath>.*\.Tests.dll$</ModulePath>
<!-- Add more ModulePath nodes here. -->
</Exclude>
</ModulePaths>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
The important part here is to exclude the test project in the ModulePaths section.
Related
We are using Swagger UI documentation to describe our project API. Swagger have to read XML from projectname.xml to show all the C.R.U.D. functions we have in project.
The problem is when I switch from Visual Studio to Visual Studio Code, it is not regenerating or changing existing XML file from Visual Studio Code. Is there the way to generate XML documentation file in Visual Studio Code like in Visual Studio Ultimate for instance, as shown the image below?
You can use the <GenerateDocumentationFile> property in the project file. This is a Boolean, and sets the DocumentationFile property automatically.
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
(Unfortunately, the Visual Studio project properties UI doesn't expose this improved way to enable XML documentation file generation yet. See this work item in the project system repo, and this pull request, which initially added the feature.)
The following is slightly more robust, it doesn't hard code the framework and project
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\$(TargetFramework)\$(MSBuildProjectName).xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
See David Waterworth's answer as it is more robust.
In your csproj file for the project, add the following.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netcoreapp2.0\TodoApi.xml</DocumentationFile>
</PropertyGroup>
Then rebuild your project.
I've created a simple xamarin studio f# project and and f# unit project. When I build I get
unknown-file(1,1): Error FS2020: The assembly
'Studio.app/Contents/MacOS/lib/monodevelop/AddIns/NUnit/nunit.framework.dll'
is listed on the command line.
Assemblies should be referenced using a command line flag such as
'-r'. (FS2020) (FRXUI.Spec)
I have made no source code changes after generating the template projects.
The problem is the space in the path to the file, the reference should read
/Applications/Xamarin Studio.app/Contents/MacOS/lib/monodevelop/AddIns/NUnit/nunit.framework.dll
There is currently a known issue here
You can also work around it by using nuget, I almost always use fsunit with NUnit for unit tests in F#. If you don't already have it, you can also get monodevelop-nuget-addin which makes installation of these packages pretty easy.
I got this too. I worked around it by replacing the reference to nunit.framework in my test project with a version built from source.
Maybe it's very easy but I'm trying to add support for xUnit in Visual Web Developer 2010 Express. I followed this tutorial on how to install everything but the main problem is that this tutorial only show how to add a test project to a new project and not to an existing one. When I do "Add New Project", there is not "xunit" or "test project" anywhere...
Anybody know how or can point me to a good tutorial?
A standard Windows Library (.DLL) project will work fine and is the normal project type used for xUnit.net Tests - all the existing mechanism really added was the inclusion of some example tests to start you off.
This (not having templates) is the approach being taken with future xUnit versions. You'll find some discussion of the reasoning behind this on http://xunit.codeplex.com/discussions
I am working on an Asp.net mvc3 project (.NET 4). And required to integrate a testing tool. I tried to setup up the Nunit testing framework in my solution but it seems that there is a problem setting it up in vs2010.
now I want to know if Nunit still works in vs2010 or
Arent there a clear testing tools for vs2010.?
tnx!
Yes, VS works only with MSTest framework. But you can use some external test-runner:
TestDriven.Net
CodeRush
ReSharper
Another option - go to NUnit GUI settings and turn on test re-running when test assembly changes. Actually I like big green bar, so I have NUnit GUI opened on separate monitor. When test assembly re-builded, all latest tests executed automatically. If I want to debug some test, I use CodeRush - match better than attaching debugger to NUnit.
NUnit has a separate test runner program. I believe the workflow with NUnit is that you code the tests in VS, but you have to run them using the separate NUnit test running program. MSTest is the only unit test framework I know of that lets you run tests from directly within VS.
However, there is a VS plugin called ReSharper. Installing that gives you an NUnit test runner within VS.
Update
Also anyone can correct me if I'm wrong here, but I believe you only get the MSTest runner with versions of VS Professional and up. I don't think VS Express comes with a built-in MsTest runner.
There's Visual Nunit that'll let you run tests from within visual studio.
There's also NCrunch, still in beta but pretty cool. From their website:
NCrunch is an automated parallel continuous testing tool for Visual Studio .NET. It intelligently takes responsibility for running automated tests so that you don't have to, and it gives you a huge amount of useful information about your tests (such as code coverage and performance metrics) inline in your IDE while you work.
I have a website written in ASP.NET MVC 3. I have put together some browser automation tests that target this website. I want to use this same set of tests to calculate the code coverage of the website code.
I know that NCover does this kind of work but based on my knowledge there are two issues. One, NCover gives code coverage figures for both framework's code and my code. Two, it's costly.
NCover has filters that you can use to ignore the framework code.
You could also use OpenCover or PartCover to get these metrics and they are both open source and free - they also have filters.
Hooking them into IIS is tricky but if it is for automation tests then you can run your tests against IIS express - much easier.