BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Automated UI Testing in .NET

Automated UI Testing in .NET

Recently DevExpress announced that they are the first third-party control vendor to achieve full support for Coded UI. So we decided to take this opportunity to talk about Coded UI and how it can play a role in building a comprehensive automated test suite.

At the core of any Coded UI test is the UI Map. The UI Map begins life as a recording of user actions (e.g. mouse clicks) much like how you would create a macro in a word processor. In addition to the steps themselves, the recording identifies user controls that you can interact with later. Here is an example of one such definition:

Note the “search properties” dialog. This is what the test runner uses to find the control on the screen. There are lots of different aspects you can use to search for, as shown below.

As the user interface evolves and tests are broken, you may find yourself modifying the search properties by hand. One way to reduce the need for this is to give key controls a Name or an AutomationId. The AutomationId was primarily created for accessibility tools like screen readers and speech recognition systems, but the same automation client technology is quite useful for this role. You can learn more about automation and accessibility on MSDN.

The UI Map also contains the “recorded methods” that form the macro. Normally you see these in a designer window, but you can convert them into raw source code. Beware though, this conversion is one way and cannot be undone.

 

Once you have your recordings fine-tuned, it is time to start writing tests. Below is an example of a simple test to ensure that a checkbox is cleared at the end of the sequence.

As you can see, the same concepts you find in unit tests apply to Coded UI tests. However, Coded UI tests do have some extra considerations. Since the tests are run against a single instance of the application, the end-state of each test may interfere with the tests that follow.

There are some useful features in Code UI for examining test results. For example, when a test fails a screen shot is automatically taken and attached to the test results.

Coded UI is only available for the Premium and Ultimate versions of Visual Studio. Strangely, Visual Studio Test Professional 2012 will not include Coded UI.

Rate this Article

Adoption
Style

BT