Visual Studio Community For Mac How To Install Nunit Test Adapter

ForNunit

I paired up with someone else who knew C#, so it was a good opportunity to try doing the kata in Visual Studio for Mac! Although I've kicked the tires on VS4Mac a bit, one of the things I hadn't tried testing out was, well. Method 1: An NUnit Library Project. The easiest method is to just create a new 'NUnit Library Project'. In NuGet Package Manager, search for the test framework you want to install, and then click Install. Update to the latest test adapters. Update to the latest stable test adapter to experience better test discovery and execution. For more information about updates to MSTest, NUnit, and xUnit test adapters, see the Visual Studio blog.

Visual Studio Community For Mac How To Install Nunit Test Adapter Kit

Visual Studio 2017 comes with a great new feature called Live Unit Testing. This feature discovers and runs unit tests while you are coding, giving you inline feedback of which tests are passing, and exactly which lines are covered by the tests.

NUnitHow

When the tests are passing you see a green tick by each line covered by at least one passing test.

How to install NUnit for C# with NuGet Package Manager on ...

When it fails you see a red cross for each line covered by the failing test, and lines that aren't covered by any tests have a blue dash.

Like I said, there's already a 'Test.cs' file ready to go, with the proper NUnit attributes and everything. Go ahead and create a regular class and add a couple tests against it. Run the tests. If you can't see the 'Unit Test' pane (or pad as they call it on the Mac), open it now: View / Pads / Unit Tests. This article will describe all aspects of NUnit starting from Test Driven Development (TDD) to converting it to data driven test. I will also show you how easy it is to compute the code coverage in Visual Studio 2015. I have briefly mentioned NUnit test with Visual Studio in one of my previous articles (Code Quality Tools in Visual Studio 2015). Install NUnit test adapter in Visual Studio Install MSBuildTasks + Nunit MSBuild task (Not sure how to use it) As a last resort, I can add a shell script to run nunit-console on the mac build agent, but I would prefer to avoid that. The reason the build agent needs mac os x is because we're building an iOS and Android app with Xamarin.

This is a great way to get rapid feedback about the code you're currently writing. I recently attempted to get it working on a large project that had lots of NUnit tests. It's not too difficult, but there are a number of gotchas that you can run into along the way, so here's my notes for what you need to get Live Unit Testing running successfully on a project with NUnit tests.

  • You do need Visual Studio 2017 Enterprise Edition, so unfortunately you can't use this with the free Community Edition.
  • You need to be using NUnit 3. Our tests were all in NUnit 2 and unfortunately there were quite a lot of breaking changes to work through.
  • When you create a new unit test assembly, it should target either the regular .NET framework (e.g. 4.6.2) or .NET Core. Don't try to put your unit tests in a .NET Standard class library - it doesn't work (perhaps because the NUnit3TestAdapter doesn't support .NET Standard).
  • Your unit test assemblies need to reference the NUnit (v3) and NUnit3TestAdapter NuGet packages
    • It's not enough to have the NUnit3TestAdapter Visual Studio extension installed - that only makes your NUnit unit tests appear in the Test Explorer window. You also need to add the NUnit3TestAdapter NuGet package to your unit test project.
  • If you've created a .NET Core unit test assembly you also need to reference the Microsoft.NET.Test.Sdk NuGet package
    • There is actually a dotnet newtemplate you can install so that you can easily create a .NET core unit test assembly with the correct references for live testing in NUnit 3 with dotnet new nunit
  • The Visual Studio Output window with 'Live Unit Testing' selected in the dropdown is a good place to look when troubleshooting why Live Unit Testing isn't working for you.
  • Live Unit Testing can be started or stopped from the Visual Studio Test menu - it doesn't run automatically.
  • You may have some tests you don't want to run as part of the live unit testing. Particularly if they are 'integration' tests that might take a long time to run or communicate with external resources.
    • You can right-click on tests, classes and assemblies, and include, exclude, or exclude all but this.
    • Unfortunately, these settings are stored on a per-user basis so you can't share these settings with the rest of your team.
    • There is a special category you can put your tests in called SkipWhenLiveUnitTesting which will exclude them from live testing. It's a shame you can't customize these rules to use the category names you're already using.
  • Once you've got it working, I should warn you it's not all plain sailing, especially on a large solution containing thousands of tests. It often seems to get 'stuck' where it's not running tests any more, or claim that tests are 'excluded' without giving clear reasons why. There are also some cryptic errors in my live unit testing output window about an invalid filter syntax, which I don't know how to resolve. The good news is that on smaller projects it seems very responsive, and hopefully some of the quirky issues will get fixed in the near future.

Visual Studio Community For Mac How To Install Nunit Test Adapter Windows 10

Here's how quick it picks up changes when you're testing in a small project which is really nice and responsive. I don't even need to save the file:

How To Unit Test Using Visual Studio For Mac (it's Easy!)

Recommended links for further reading: