filter unit tests in test explorer in visual studio 2012 by both property name and value

1k views Asked by At

Is there a way to filter tests in test explorer in visual studio 2012 by both property name and property value. Consider following properties on 4 distinct tests:

[TestPropertyAttribute("A", "1")]

[TestPropertyAttribute("B", "1")]

[TestPropertyAttribute("A", "2")]

[TestPropertyAttribute("B", "2")]

Is there an expression I can put in test explorer filter bar that will only how me tests that have property B with value 1? Something like: trait:B=1.

I know I can use trait:B to show all tests that have property B defined, or a property with value set to B. But I want to know if there is a way to only get tests decorated with:

[TestPropertyAttribute("B", "1")]
1

There are 1 answers

0
Klaus Stefan Gerber On

There is no direct way of doing this, but there are several workarounds that can be used to achieve your needs.

1. If you don't have any other traits (TestPropertyAttribute, TestCategory, Priority or Owner) on your tests, you can do it by defining two filters like this:

Trait:"B" Trait:"1"

But you have to be careful, because that filter would also return all of theses tests:

[TestPropertyAttribute("B", "1")]
[TestPropertyAttribute("B", "10")]
[TestPropertyAttribute("B", "100")]
[TestPropertyAttribute("B", "21")]
[TestPropertyAttribute("B", "31")]

So in that case you would need to add some leading zeros to solve the problem:

[TestPropertyAttribute("B", "001")]
[TestPropertyAttribute("B", "010")]
[TestPropertyAttribute("B", "100")]

So you could use arcodingly with the filter:

Trait:"B" Trait:"001"

2. If you are using other traits (TestPropertyAttribute, TestCategory, Priority or Owner) you have to be more specific with your own TestPropertyAttribute.

Let's say you also have a numeric property which can be confused with your "B" trait Value. So you have to add the "B" to your trait value like this:

[TestPropertyAttribute("B", "B001")]

So you could be filtering then the following way:

Trait:"B001"

Additionally

Would recommend to read the following blog which has very useful information regarding this topic:

How To Manage Unit Tests in Visual Studio 2012 Update 1 Part 1 Using Traits in the Unit Test Explorer