A Quick Introduction to Visual Studio’s Coded UI Tests

A question that is raised in many development shops is “How can we test our application front to back?”. One solution I have been looking at is using an underrated feature of Microsoft Visual Studio Enterprise called Coded UI Tests. This feature allows a developer to record steps, and write code, to interact with their application by simulating a user experience. Behind the scenes, the tests are generated in C#. Having the steps coded in C# makes it simple for a developer to follow and manipulate.
Let’s take a look at a simple use case.

Setting up a project

In order to get started you first have to install Visual Studio Enterprise. As of this writing, Coded UI Tests are not supported in any other versions.
Next up, add a Coded UI Test project to your solution

After the project type is select, the below window will popup and you can select the first option.

Now you should see the UIMap window. This is where the magic starts.

Click the red button to begin recording the user simulation.
Populate textboxes and click buttons just like a user would.
Click the generate code button. Visual Studio will create a UIMap and a UIMap.Designer file. These files should now display everything you just simulated.

Now that you have mapped out the actions a user has taken, we can inspect the state of the application. Click on the Assertion button to programmatically inspect the application.
You will see a list of all of the controls on the page. If you don’t see something, hover your mouse over the control and type Ctrl + Shift + I. You should now see all of the properties for that control and can add new assertions.

After you add your assertions on the UIMap window, click the generate code button.
You now have a class that lists out all your steps and assertions. Here is an example of my invalid login test

        public void LoginInvalid()

Notice this looks just like any other C# test. At this point, we could add custom logic around the UI test. For example, a username/password could be read from a config file.
Hopefully, this gives you enough to get started on creating and understanding Coded UI Tests. If you would like to dive deeper, check out the following MSDN articles for more great tips and tricks:
Main MSDN article: https://msdn.microsoft.com/en-us/library/ff398062.aspx
Best practices: https://msdn.microsoft.com/en-us/library/dd380782.aspx

Share on

Facebook sharing Linkedin sharing button Twitter sharing button

Ready to get started?

Enter your information to keep the conversation going.
Location image
4 Sentry Parkway East, Suite 300, Blue Bell PA, 19422

Email Image


Phono Image610 239 8100

Location Image4 Sentry Parkway East, Suite 300, Blue Bell PA, 19422
Phono Image610 239 8100