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()