Create and Run Subset of Unit Tests Using Playlist in Visual Studio

Create and Run Subset of Unit Tests Using Playlist in Visual Studio

Visual Studio Unit Test Tools  comes with an another excellent feature to manage unit test as a group /subset,  called as “Playlist”. A Playlist is a sub set of unit test methods grouped under some category. This could be a logical subset based on modules, features, layers etc.  This is really useful when we want to test very specific set of test cases among all the test methods. In that case, we just create a group of those test cases which may get impacted by our current changes in the actual code, and execute them only to ensure nothing breaks.

You can create a playlist either from the Test Explorer or from the main menu by navigate to Test –> Playlist.  Let’s have a look how we can do that.

  • Step 1 : Select Unit Test methods together for which you want to create a playlist.
  • Step 2 : Navigate to Add to Playlist –> New Playlist
Create a Playlist
Create a Playlist

Once you select the “New Playlist”, a Create new file dialog will come up where you need to specify the name of the playlist file.

Save Playlist File
Save Playlist File

And That’s all ! You are Done !

You can then group by / run your test based on the playlist you have created.

New Playlist
New Playlist

Once a playlist is selected, all the filters, grouping and other operation on unit test would be applied only to the playlist.

image image

 What does a playlist file contains ?

The unit test playlist is nothing but a XML file that contains the list of all added unit test.  Here is how a general test file looks like ( Opened in Visual Studio Code )

Playlist Contents
Playlist Contents

Adding Unit Test to existing Playlist

To continue adding test to the playlist you should use the top Menu to select “All Tests”, find tests you want to add to the playlist, and simple right click and choose to “Add to Playlist”; now you should see all the testlist of the project and not only the “new Playlist” option.

 

Adding Unit Test To Existing Playlist
Adding Unit Test To Existing Playlist

Hope this helps

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

One Comment to “Create and Run Subset of Unit Tests Using Playlist in Visual Studio”

Comments are closed.