Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
593 views
in Technique[技术] by (71.8m points)

unit testing - How to exclude certain tests in the Visual Studio Test Runner?

I have attributes on certain tests that I ideally don't want to run on every build. Most of my tests are normal unit tests and I do want them to run on every build.

So: how can I exclude a test by category or project type?

For example, I'd like to exclude CodedUItests:

[CodedUITest]
public class SearchViewTests

...or exclude tests in a given TestCategory:

[TestMethod]
[TestCategory("Database Integration")]
public void ContactRepositoryGetByIdWithIdExpectCorrectContact()

I particularly want to exclude the coded UI tests as they disrupt my ability to continue working, whereas all the other tests will happily run in the background without disturbing me.

Originally this question was about Visual Studio 2012, so I'd prefer solutions that work in that version and higher.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

TL;DR version:

Test explorer showing -Trait:"CategoryName" filter

Other answers have commented on workarounds and use of the more recent Traits options. However, none quite tell you how to specifically exclude tests for a trait. To do so, simply use a - (minus) to negate a filter in the search box, e.g.:

-Trait:"DatabaseIntegration"

This will exclude all tests with that trait. The MSDN documentation on these features has the following explanation:

To exclude a subset of the results of a filter, use the following syntax:

FilterName:"Criteria" -FilterName:"SubsetCriteria"

For example,

FullName:"MyClass" - FullName:"PerfTest"

returns all tests that include "MyClass" in their name except those tests that also include "PerfTest" in their name.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...