As an application gets bigger throughout the life of the project, more and more tests have to be repeatedly performed to ensure that the recent development work hasn’t introduced any new bugs. It’s not unrealistic to have 100 tests to be run across 4 different environments on 10 builds. That is a lot of manual test execution. The real challenge kicks in when all of it needs to be completed before a specific deadline but you have limited resources and lots of new features to test.
There are different ways to automate the testing process. One way is to record our test and verify the results with automation. We can quickly generate a coded UI test by recording our actions in the application using Visual Studio Ultimate 2013.
First, let’s record a test. In Solution Explorer, right-click a test project, point to Add, and then click Coded UI Test.
Then, select “Record actions, edit UI map or add assertions” and click OK. The Coded UI Test Builder dialog box appears.
To start recording, click the Record icon. Perform the actions that you want to record in your application. I recorded adding two numbers in a calculator.
To finish recording, click the Generate Code icon. Next, Type a name for your coded UI test method in Method Name, and then click Add and Generate.
This generates code to
(1) Add the controls and UI map (UIMap.uitest)
(2) Add a method to UI map which performs the actions that you recorded during the test.
Now your test is recorded.
Next, let’s check how to verify that the result is what we expected using assertions. In order to generate assertions for UI controls, click the crosshairs icon and drag it to the control that you want to verify is correct. This opens the Add Assertions dialog box.
Click on a property, then click Add Assertion.
Select the comparator for your assertion, type in a value for comparison value and click OK. When all the required assertions for the test are added, close the Add Assertions dialog box. Click the Generate Code icon to generate code for the assertion you created, and the Generate Code dialog box will pop up. Type a name click Add and Generate.
Click the Close icon to close the Coded UI Test Builder. Now run the test, right-click on the test method, and click Run Tests.
Posted by Brian Pohl