简体   繁体   中英

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?

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.

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM