VS 2010 and Nunit testing framework setup - asp.net-mvc

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.

Related

Is it possible to do code coverage analysis with Visual Studio 2019 when running manual tests

I have a web application developed in Visual Studio 2019 (free Community edition), running on .NET Core 2.2
Because it's a web app, unit tests don't really help. But I would like to see if I have tested all the code when doing manual testing. Is this possible?
If you care to suggest a way of automating the testing of a complex web app, that would be nice, provided it isn't too open ended a question.

.net core projects code coverage visual studio 2017

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.

How to order NUnitLite tests (for integration testing)?

We are trying to port integration tests that are using NUnit to NUnitLite provided with Xamarin. Some of the tests should run in a particular order. However it looks like there no OrderAttribute or any dependency attribute present in NUnitLite.
Are there any approach for running tests in an order on iOS and Android?
NUnit 2.6.4 and 3.0 runs tests in alphabetical order. Since the Xamarin NUnitLite code is a fork, it may behave the same.
Another option is to use NUnit 3's Xamarin runner. NUnit 3.2 added an Order attribute and I will be updating the Xamarin runner to use 3.2 shortly. For more information on using the Xamarin runner and NUnit, see Testing Xamarin Projects using NUnit 3

Add xUnit test project to an existing Visual Web Developer 2010 express MVC application

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

What tools are available for calculating code coverage using browser automation tests

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.

Resources