Assign multiple test categories using TestCategoryAttribute

Posted by Michael Freidgeim on Geeks with Blogs See other posts from Geeks with Blogs or by Michael Freidgeim
Published on Sun, 30 Sep 2012 00:36:27 GMT Indexed on 2012/09/30 3:38 UTC
Read the original article Hit count: 441

Filed under:
I am using TestCategoryAttribute to filter which tests to run during builds and wandered, how to -how to assign multiple test categories.
According to constructor documentation only single category can be specified.  However TestCategories Property (plural!)can return multiple categories.

Grouping Tests into Test Categories: You can add an automated test to one or multiple test categories using a test attribute. Each test can belong to multiple test categories.
The recommended approach from MSDN How to: Group and Run Automated Tests Using Test Categories is to specify multiple TestCategory attributes like the following

[TestCategory("Nightly"), TestCategory("Weekly"), TestCategory("ShoppingCart"), TestMethod()]
public Void DebitTest() { }
shows how enums can be used instead of strings.
It also explains, that TestCategories Property can be used in derived custom attributes.v

© Geeks with Blogs or respective owner