When you choose Generate Code, several pieces of code are created:
- A line in the test method.
[CodedUITest] public class CodedUITest1 { ... [TestMethod] public void CodedUITestMethod1() { this.UIMap.AddTwoNumbers(); // To generate more code for this test, select // "Generate Code" from the shortcut menu. } }
You can right-click in this method to add more recorded actions and verifications. You can also edit it manually to extend or modify the code. For example, you could enclose some of the code in a loop.You can also add new test methods and add code to them in the same way. Each test method must have the [TestMethod] attribute. - A method in UIMap.uitestThis method includes the detail of the actions you recorded or the value that you verified. You can edit this code by opening UIMap.uitest. It opens in a specialized editor in which you can delete or refactor the recorded actions.You can also view the generated method in UIMap.Designer.cs. This method performs the actions that you recorded when you run the test.
// File: UIMap.Designer.cs public partial class UIMap { /// <summary> /// Add two numbers /// </summary> public void AddTwoNumbers() { ... } }
Caution You should not edit this file, because it will be regenerated when you create more tests.You can make adapted versions of these methods by copying them to UIMap.cs. For example, you could make a parameterized version that you could call from a test method:// File: UIMap.cs public partial class UIMap // Same partial class { /// <summary> /// Add two numbers – parameterized version /// </summary> public void AddTwoNumbers(int firstNumber, int secondNumber) { ... // Code modified to use parameters. } }
- Declarations in UIMap.uitestThese declarations represent the UI controls of the application that are used by your test. They are used by the generated code to operate the controls and access their properties.You can also use them if you write your own code. For example, you can have your test method choose a hyperlink in a Web application, type a value in a text box, or branch off and take different testing actions based on a value in a field.You can add multiple coded UI tests and multiple UI map objects and files to facilitate testing a large application.
To see next Coded UI post please click the link