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
[TestMethod] public void LoginInvalid() { this.UIMap.LoginInvalid(); this.UIMap.AssertInvalidLogin(); }
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
Related Content
by Brian Slocum
Brian Slocum
Senior Consultant
Brian Slocumis a seasoned Anexinet developer who provides groundbreaking custom solutions from development to deployment across multiple platforms and languages.
Let’s get the conversation started
Reach out now to begin your digital transformation
+ 16,659
ZOOM MEETINGS
+ 9,789
HAPPY CLIENTS
+ 5,075
FINISHED PROJECTS
+ 133,967,432
LINES OF CODE
© 2000 - 2021 Anexinet Corp., All rights reserved | Privacy Policy | Cookie Policy
This website uses cookies
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL cookies.
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.