Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Test Explorer with playlists

This may be related to question: Dynamic playlists of unit tests in visual studio.

I want to be able to have one or more playlists of tests and not have not add every single new test to a certain playlist.

I currently have one playlist containing all my unit tests, but in the future I want to have a playlist consisting of automated integration tests, which should be run before committing to TFS but not every time the application builds.

Is there a way to do this?

like image 670
Alexander Avatar asked Nov 10 '15 06:11

Alexander


People also ask

How do I create a playlist in Visual Studio test Explorer?

To create a playlist, choose one or more tests in Test Explorer. Right-click and choose Add to Playlist > New playlist. To open a playlist, choose the playlist icon in the Visual Studio toolbar and select a previously saved playlist file from the menu.

Which is better NUnit or MsTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.


1 Answers

Im not aware of the types of settings you can use in TFS, since Im not using TFS, but I know it is possible using Categories in both, NUnit and MSTest.

Solution With NUnit

With NUnit, you can mark single tests or even the whole fixtures with a Category-Attribute:

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  [Category("IntegrationTest")]
  public class IntegrationTests
  {
    // ...
  }
}

or

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  public class IntegrationTests
  {
    [Test]
    [Category("IntegrationTest")]
    public void AnotherIntegrationTest()
    { 
      // ...
    }
  }
}

and the only run those using nunit-console.exe:

nunit-console.exe myTests.dll /include:IntegrationTest

Solution with MSTest

The Solution for MSTest is very similar:

namespace MSTest.Tests
{
    [TestClass]
    public class IntegrationTests
    {
        [TestMethod]
        [TestCategory("IntegrationTests")
        public void AnotherIntegrationTest()
        {
        }
    }
}

But here you have to mark all Tests with that attribute, it cannot be used to decorate the whole class.

Then, like with NUnit, only execute those tests in the IntegrationTests-category:

Using VSTest.Console.exe

Vstest.console.exe myTests.dll /TestCaseFilter:TestCategory=IntegrationTests

Using MSTest.exe

mstest /testcontainer:myTests.dll /category:"IntegrationTests"

EDIT

You can also execute certain Test-Categories using the TestExplorer of VS.

enter image description here
(source: s-msft.com)

As seen in the above image, you can select a category in the top left corner of the TestExplorer. Select Trait and execute only the catgegory that you want to.

See MSDN for more Information.

like image 154
nozzleman Avatar answered Sep 22 '22 01:09

nozzleman