Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Live Testing not working with NUnit

Tags:

When I turn on Live Testing my tests show "Excluded from live unit testing". This only happens if I use NUnit, using MSTest works fine.

I have: Visual Studio Enterprise 2017 (15.6.2) NUnit 3.10.1

A brief example of code

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
        }
    }

    [TestFixture]
    public class NUnitTest1
    {
        [Test]
        public void NUnitTestMethod1()
        {
        }
    }
}

TestMethod1() has a green checkmark next to the beaker indicating Live Unit testing is on and covered by a test. NUnitTestMethod1() has the beaker, but no checkmark and mousing over it shows "Excluded from live unit testing".

What am I missing? Outside of me adding NUnit through Nuget and adding the extra test class/method there were no other edits or changes done. I'm running on a fresh install of Visual Studio where the only other thing added is ReSharper Ultimate (2017.3.2).

like image 670
gilliduck Avatar asked Mar 19 '18 13:03

gilliduck


1 Answers

You cannot mix two test frameworks in one project. Visual Studio checks each installed test adapter to see if it handles the given test project. Once it finds one that works, it stops checking the others. In your case, the MSTest adapter will be used and since the MSTest adapter doesn't understand NUnit tests, it will not run those tests.

Create a separate NUnit test project, ensure you don't reference MSTest and add NUnit 3.10.0 and the NUnit3TestAdapter 3.10 NuGet packages to your project. If you are using .NET 4.x, that should get you up and running. If you are targeting .NET Core, see the NUnit docs for more information, https://github.com/nunit/docs/wiki/.NET-Core-and-.NET-Standard

This is live unit testing of an NUnit project in 15.6.2. Notice the green checkmarks.

enter image description here

like image 131
Rob Prouse Avatar answered Sep 23 '22 12:09

Rob Prouse