When you have a large number of tests, you need some way to execute just one or a subset of the tests. The UTF includes a tagging language, which allows you to create tag expressions that specify which tests should be run during a unit testing session.
Every test class and test method has an implicit set of tags, shown in the following list:
Type or method name, for example, TestClass1, TestMethod1.
Full type or method name, for example, TestClass1.TestMethod1.
The priority specified by a Priority
attribute if present. For further information on tag expressions and the Priority
attribute, see the section “Priority
Attribute” later in the chapter.
You can also explicitly assign a test class or test method with a tag, using the Tag
attribute. The Tag
attribute accepts a single string parameter, which is used to associate a test with a group of tests.
The following is an example of a test method decorated with a Tag
attribute:
[TestMethod]
[Tag("UITest")]
public void AlwaysPass()
{
Assert.IsTrue(true, "Test method intended to always pass.");
}
Multiple Tag
attributes can be applied to any test class or method in your test suite. Tags can also be useful in selecting different kinds of tests to run.
When the testing session begins, you have the opportunity to enter a tag expression. To run the test method from the previous excerpt, or any other test methods with a matching attribute, you could enter UITest
as the tag expression.
The tag expression syntax provides a set of operators to control test selection. The !
(not) operator, for example, allows you to prevent those tests with a particular tag from being executed. A tag expression of !UITest
causes all tests that do not have the tag UITest
to be executed. A tag of All-(UITest+IntegrationTest)
causes all tests that do not have the UITest
or IntegrationTest tag to execute.
The tag expression syntax uses Extended Backus-Naur Form (EBNF). You can use the symbols presented in Table 24.1 in tag expressions.
18.191.168.8