What is PriorityAttribute Used for in MSTEST / Visual Studio
-
05-07-2019 - |
Question
I noticed the existence of Microsoft.VisualStudio.TestTools.UnitTesting.PriorityAttribute. From reading a little about it, it does not seem to have anything to do with the test execution order. That being the case, it begs the question: what is it used for?
I'm curious, are there any known uses of this attribute either by Visual Studio itself of any plugins/frameworks.
Solution
Its just extra metadata its not used for anything specific right now. The only thing that impacts the ordering of tests is using an ordered test
OTHER TIPS
It can be used in Build Definitions (for builds on a build server) to exclude or include unit tests (a least in tfs 2010).
In the Visual Studio 2012 Test Explorer tool window, both test priorities and test categories are shown when you select the "Traits" view. Tests with the same priority will then be grouped together under a Priority [x]
heading, just like test categories.
Also, mstest (the command line test runner included in visual studio) allows you to run only tests with a minimum priority. From the output of mstest.exe /?
:
/minpriority:[priority] Only tests whose priority is greater than
or equal to this value will be executed.
Example:
/minpriority:0 /maxpriority:2