Thursday, September 30, 2010

Coded UI Tests: Test Lists, Test Categories, Oh My!

This is part 2 of a series of blog posts covering Coded UI Tests. This post will assume you’ve read part 1: how to create a coded ui test.

As a test suite is getting built, organization is very important. It’s very important in order to I’ll show you two different ways to organize Coded UI Tests, through test lists and test categories. There’s an xml file that stores the mapping of test lists to tests in a .vsmdi file that’s associated with your solution. This allows us to create test lists that cross projects or even within the same project.

Organizing your tests offers many benefits including easier to locate the test in addition to helping with running Coded UI tests from the command line (which I’ll discuss in a later post).

Test Lists:

One test method can belong to multiple test lists. You can also create a hierarchy test list structure, test lists inside of a test list. Test methods can be run by calling the test list, however, the order in which the test methods execute in the test list are not guaranteed to be in any certain order.

How to create a new test list:

1. Load a Coded UI Solution

2. Open up the “.vsmdi” file in the solution.

3. This will open the “Test List Editor” window

4. Right Click on the “Lists of Tests” and create a new test list. We’ve named this “LoadCalcTestList” and click “OK”

5. This will add it under your “Lists of tests” like so.

6. In order to add a test to a test list, open up the Test View Window (Test->Windows->Test View)

7. Click and drag the “LoadCalculator” test into the “LoadCalcTestList” tree item in the Test List Editor like so.

Test Categories

One test method can belong to one or multiple test categories. Just like test lists, you can run a category of tests but the order in which test methods are executed are not guaranteed.

These test categories are effectively attributes above the test method. Programmatically, a test category looks like the following code snippet:

[TestCategory("CalcCategory"), TestMethod]
public void LoadCalculator()

This will show the GUI way on adding Test Categories:

1. In order to add a test to a test category, open up the Test View Window (Test->Windows->Test View) and highlight the test.

2. In the properties section, there’s a “Test Categories” property. Click on “…” eclipse button. This will load the following window and input the following information:

3. Click “Add” and it will put the “CalcCategory” into the “Assigned Categories” list and click “OK”.

Download Sample Coded UI Solution

1 comment: