Data Driven Coded UI Test using Visual Studio 11
Posted by: Gouri Sohoni
in Category Visual Studio
Abstract: In this article, we will see how to convert normal Coded UI Test to Data Driven Coded UI Test using Visual Studio 11.
In this article, we will discuss in detail how to convert a normal Coded UI Test (CUIT) to Data Driven CUIT. CUIT is a new type of unit test introduced with Visual Studio 2010 Ultimate/Premium version. It provides functional testing for the user interface and the code gets created with the help of high level languages like C# or VB.NET.
If you are new to Coded UI Tests, make sure you read the following articles written for Visual Studio 2010.
Coded UI Test (CUIT) using Visual Studio 2010
Coded UI Test (CUIT) - Convert Manual Test Case to Code using Visual Studio 2010
Coded UI Test (CUIT) – Variations and Editing with Visual Studio 2010 and
Coded UI Test: Convert Normal CUIT to Data Driven CUIT using Visual Studio 2010.
Visual Studio 11 Beta can be downloaded from over here where all the SKUs (Ultimate, Premium, Professional or Test Professional) are available. Here is a snippet comparison between various SKUs and whether Coded UI Test support is available in them
The main difference while converting a normal CUIT to Data Driven CUIT with Visual Studio 11 is that there is no Data Source Wizard (which was available with Visual Studio 2010).
We will now create a normal CUIT and later convert it to Data Driven CUIT. For this we will use the example of a calculator and record addition of 2 numbers. We will use number keys to enter the numbers.
Follow these steps:
Step 1: Open Visual Studio 11 > File > New Project. A new project template for Coded UI Test project is available as shown
Step 2: As we are going to use the CUIT Builder, we will select the first radio button for creating a Coded UI Test (Record actions, edit UI map or add assertions)
Step 3: The CUIT Builder with a slightly changed look appears in the default position (right most bottom portion of the screen)
Step 4: Start Calculator
Step 5: Record addition of 2 numbers. Note: Do not use the mouse click to capture data as we do not get parameters with this action later
Following are the methods recorded.
We can also provide method description which will appear as a comment in the method
Step 6: With Visual Studio 11, we now have Unit Test Explorer which will show the available test methods. Run the test and verify that it gets executed without any error.
Step 7: Add a new item to the project. Provide NumData.xml as file name for the XML data file. Change the property for the file from Copy to Output Directory to “Copy if newer”
Step 8: We also need to provide the DataSource attribute to the method so as to specify the xml file as the data source. The parameters values can now to be taken from the data source as shown below
Step 9: Now run the test and we can observe that it passes for 2 records but fails for one.
Note: If you use a mouse click while entering numbers, no parameters will be automatically provided. This will also work only with single digit numbers.
In this article, we have seen how to convert normal Coded UI Test to Data Driven Coded UI Test using Visual Studio 11.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce the The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this eBook aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on .NET Standard and the upcoming C# 8.0 too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!