Automated UI Testing in .NET

by Jonathan Allen on Jul 05, 2012 |

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.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

But their Unit Test Runner does not support CodedUI Test by Yetao Chen

I just submit a support issue days ago

What their feedback is:
'We appreciate your feedback. Unfortunately, this is a current limitation of the CodeRush Unit Test Runner. It does not support CodedUI tests. We are going to eliminate this limitation by implementing the mentioned support with one of our future releases.'

Link is there:

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

Personalize Your Main Interests

    Architecture & Design
    Process & Practices
    Operations & Infrastructure
    Enterprise Architecture

This affects what content you see on the homepage & your RSS feed. Click preferences to access more fine-grained personalization.

General Feedback
Editorial and all content copyright © 2006-2015 C4Media Inc. hosted at Contegix, the best ISP we've ever worked with.
Privacy policy