Visual Studio 2010 - Functional Testing

10/28/2009

閱讀時間 10 分鐘

本文內容

Visual Studio Team Test is part of the Visual Studio 2010 that encapsulates a suite of testing tools for Application Lifecycle management. Some of the features of VSTT are the ability to create Unit Tests, Web tests and Load tests for Performance and Stress testing, more importantly the Functional Testing capabilities that addresses the needs of both Manual and Automated testers. The following note will explain in detail about the Functional Testing features in Visual Studio for Automated testers. This is achieved through the UI Automation techonologies along with Record and Playback framework.

CodedUITest:

Visual Studio 2010 introduces a new test type – Coded UI Test [CUIT] , which enables you to create automated UI tests which can then be added to a regression test suite. Coded UI Tests may be run as part of a Build Verification Test suite, thus giving the developer immediate feedback on any UI regressions. The developer can run these UI Tests before his check-in and ensure that there are No more UI regressions.

It supports the following tools

1. Coded UI Test recorder allows users to record test actions and generate code for them. Generated code is re-factored into methods based on user gestures

2. UI Control Locator allows users to add UI controls to a repository and generate assertion code on their properties

3. Coded UI Test has excellent integration with Team Foundation Server

The following sub-sections provide details on the features supported by the engine.

· Intent-aware, non-intrusive and resilient action recording: Instead of just capturing raw user actions, the engine has been designed to be intent aware. Set of actions are aggregated into equivalent action to provide an intent aware playback.

Additionally, the engine uses smart algorithms to accommodate changes in configurations like window resize/Minimize/Maximize, screen resolution changes etc to provide a resilient playback support.

· Strong UI technology and platform support: The engine supports a wide range of platforms out-of-the box covering thick client applications built with .Net technologies to latest web applications

Internet Explorer 7.0 and Internet Explorer 8.0

Support for applications written in ASP.Net, PHP, JSP, ASP, Ajax, SharePoint and other Web 2.0 applications.

Win-forms Controls for Microsoft .Net framework 2.0, 3.5 SP1 and 4.0. Win32 / MFC controls with good accessibility.

Windows Presentation Framework (WPF) for .Net framework 3.5 SP1 and 4.0

Internally the engine uses features of IEDOM for recording actions on the web applications being tested via Internet explorer. It uses accessibility technologies in Windows to capture actions on AUTs. Specifically it uses Microsoft Active Accessibility (MSAA) for Win-form support and UI automation (UIA) for WPF support. Custom controls that are developed for Win-form and WPF that follow accessibility guideline are also supported.

· In-built sophisticated mechanisms for handling complex UI action recording scenarios

Fast Search: In order to be able to playback user actions, the engine must be able to search for the Control that was acted upon. It uses fast search algorithms to quickly identify the controls and take appropriate actions on them.

Wait For Ready Mechanism: When playing back an action the engine needs to know that the UI is ready to act on the next action. For example, if the application was navigating to a web page, the engine needs to wait for the navigation to complete before taking an action. The WaitForReady mechanism provides this support by intelligently detecting the application’s readiness to act on the next action.

UI Synchronization: If the user acted on a control (e.g. a mouse click), the engine needs to ensure that the control actually did receive the input. UI synchronization feature provides this support to the engine allowing it to perform a more resilient playback.

Ensuring UI Control is Visible: In a fast-forward scenario, the UI element (e.g. a list box) that needs to be acted upon might not be visible (scrolled our) or hidden behind another window. This feature ensures that the element is visible before taking an action on it.

How is CUIT different?

CodedUITest has an edge over the existing automation Frameworks in terms on the following

1. Robustness

2. Scalability in different dimensions like number of actions, number of controls and the length of the recording and playback

3. Performance of the Automation

4. Breadth in Platform Support

5. Integration with Visual studio Team System for Planning, Authoring, Executing test cases and Reporting.

To get more insight on the comparison with other automation frameworks, visit the UI Automation Wiki page here [Microsoft internal link]

Creating Automated Functional Tests using CUIT:

A typical functional test encompasses a series of Actions to be performed on the application under test followed by set of Validations that will verify the functionality of the test application at that stage of execution.

The following are the steps to be followed to create a CodedUITest. The underlying sample application is a Form-filling application.

1. Start Visual Studio 2010 IDE

2. Click on “Test” menu and select “New Test”

3. Selected “CodedUITest” from the list of available test types and create a Project

Note: It is preferable to add the Test project to the Application’s solution itself so that the Test code will be built as part of the product code build process.

Screenshot of the Application under Test:

Recording the actions and Generating code for Automated Test:

1. From the Dialog that opens on creating a new instance of CUIT, Select “Record Actions, Edit UIMap or Add Assertions”

2. CodedUITest Builder Window opens just above the task bar with 4 buttons [ Record/Pause, View Actions, Add Assertions, Generate Code ]

3. Click on “Record” and Start performing actions on the Application.

In this example of Form-Filling Application, we will be keying in the details for Name, DOB, Sex and Profession fields and Click on Submit to generate some results

4. Now that we have recorded the application, we need to generate code for the recorded actions to create an automated test for the underlying scenario. To do so, Click on “Generate Code”

5. Key in a Name for the Method and Click on “Add and Generate”

Inserting Assertions for validations:

1. Any functional testing scenario is complete only if the validation is done for the actions done on the application. In our example, we will be validating the Output of the Results Textbox at the bottom.

2. To Insert Assertion, Click on “Add Assertion”. This opens up CodedUITest Builder in Assertion mode.

3. The Window has 2 panes.

a. Left pane shows all the controls interacted till now. This is called UIMap Viewer.

b. Right pane shows all the Properties of the selected control. This is called Property Explorer.

4. To add validation for a control that is already added to UIMap

a. Click on the control in Left pane. Select the validation property. Right Click on it and Click “Add Assertion”

b. In order to undo adding Assertion on the same session, Right Click on the property to select “Delete Assertion”

5. To add validation for a new control

a. Point to the control on the Application. Use the Global Hot-key for Add Control to UIMap [ Win + I ]

b. Same as above, select the validation property to Assert on and Key in the Assert Value in the dialog that opens up.

6. Click on “Generate code” to generate the code for the Assertion added.

Code Snippet of the generated assertion:

///

/// CheckResult - Use 'CheckResultExpectedValues' to pass parameters into this method.

///

public void CheckResult()

{

WinEdit rtbDetailsEdit = this.FormFillingApplicatiWindow.RtbDetailsWindow.RtbDetailsEdit;

// Verify that 'rtbDetails' text box's property 'Text' equals 'You are Hari born on 19 July 1988 working as Engineer

Assert.AreEqual(this.CheckResultExpectedValues.RtbDetailsEditText, rtbDetailsEdit.Text);

}

Contents of CodedUITest Project:

1. UIMap.uitest – This is a xml file that is a repository for the UIObjects interacted in the test and the list of Recorded and Assertion methods added to the test

2. UIMap.Designer.cs – Auto-generated file [ Not to be edited by the users ] , which contains the Class definitions of the UIObjects in the UITest

3. UIMap.cs – Partial class, which is a place-holder for overriding the properties of the UIObjects in UIMap

4. CodedUITest.cs – Test Class that instantiates the UIMap in the current project and calls the Recorded and Assertion methods

5. UserControls.cs – Control Type classes for each of the types of the UIObjects added to the UITest file

a. In case of a Winforms button, the generated UserControls class name will be WinButton

Finally, run the test to verify the scenarios / validations and hence the functionality of the application will be tested.

Maintainability of CodedUITest:

Any Application’s User interface is subject to change over the product cycle. This adds up to the maintainability cost of the automated functional tests.

In the context of CodedUITest, the recorded actions and assertions are code-generated on the controls in the application, which are found through a set of properties called “Search and Filter Properties”. In many instances, the functional tests are not agnostic to the changes in the application. So, the changes in the functional tests are highly vulnerable. The following segment will explain in detail about the series of the recommended steps that needs to be followed for fixing the CodedUITest for a corresponding change in the application.

What are the possible changes in the Application that will affect CodedUITest?

1. Change in the Expected Value of the Validation Property

2. Change in Value of the Search Properties.

3. Change in the UI Hierarchy of the control [ like moved to a different container ]

How to deal with changes in Validation properties:

1. The obvious solution would be to make the CodedUITest fail because of incorrect expected value. On the Error Stack Trace in Test results window, Click on the Assertion line link and fix the Expected value.

2. CodedUITest generated code has a Partial class from which the tester will have access to Recorded methods, Assertion methods and the ExpectedValues classes. So the other way to fix the expected value is to write an Initialization function that will change the expected value of the assertion. See sample code below

//Partial Class Code

public partial class UIMap

{

///

/// Method to set the Expected value to String.Empty

///

public void Init()

{

this.CheckResultExpectedValues.RtbDetailsEditText = String.Empty;

}

}

//CodedUITest Class Code

[TestMethod]

public void CodedUITestMethod1()

{

UIMap map = new UIMap();

//Call Init() to reset the Expected value

map.Init();

//Call Assertion method

map.CheckResult();

}

How to deal with changes in Search properties:

Any change in Search Properties will result in failure of Recorded methods as well as the assertions added, as both are dependent on the Search properties of the underlying control.

1. One of the recommended solutions is to re-fetch the control to the UIMap. Add the new control to the UIMap and generate code to reflect the changes of the UIMap in the code. To update the code replace all instances of the old object with the new object added.

a. This can be done by copying the “Reference of the new and old Object to clipboard” and do a Find-replace in the Test project

b. You may also delete the old object from the UIMap by clicking on the “Delete” button on CodedUITest builder toolbar. This can be done only when no references to the object is present in the test classes.

c. Note that, we need to generate code from updated UIMap to remove the obsolete UIObjects in UIMap.Designer.cs file.

2. Search properties can be overridden inside the Partial class using some Initialization methods. See sample code below

///

/// Method to override the Search properties in UITest

///

public void ChangeProperties()

{

this.FormFillingApplicatiWindow.SubmitWindow.SearchProperties[WinProperties.Window.Name] = "SubmitDetails";

}

//CodedUITest Class Code

[TestMethod]

public void CodedUITestMethod1()

{

UIMap map = new UIMap();

//Call ChangeProperties () to change the search properties

map.ChangeProperties ();

//Call Recorded method

map.Bvtmethod();

}

3. The last resort would be edit the UITest [xml formatted] file directly and “Generate Code” for the changes to reflect in UIMap.Designer.cs file. This is not the recommended way as editing the UITest incorrectly may result in incorrect functionality.

Ready to try out CodedUITest?

Visual Studio 2010 Beta2 is available in this link.

vs2010 ajax客户端,Visual Studio 2010 - Functional Testing相关推荐

  1. 微软MSDN中文网络广播(Webcast)——Visual Studio 2010 ALM应用实践系列课程预告(2011)...

    Visual Studio 2010 & ALM应用实践系列课程:(将在2011年3月前录制完成) 本系列课程较完整的覆盖了基于Visual Studio 2010 & ALM来进行软 ...

  2. VS2010中文旗舰版下载 Visual Studio 2010 Ultimate

    Visual Studio 是微软公司推出的开发环境.是目前最流行的 Windows 平台应用程序开发环境.目前已正式发布的是 9.0 版本,也就是 Visual Studio 2008,而在2008 ...

  3. VS2010与.NET4系列 23.Visual Studio 2010 扩展管理器(和新的 VS2010 PowerComman

    今天介绍VS2010中的扩展能力改进,以及一个微软发布的"PowerCommands for Visual Studio 2010"扩展. VS2010中的扩展能力 VS2010比 ...

  4. Microsoft Visual Studio 2010(VS2010)秘钥

    Microsoft Visual Studio 2010(VS2010)正式版 CDKEY / SN: YCFHQ-9DWCY-DKV88-T2TMH-G7BHP 企业版.旗舰版

  5. win7配置C语言VS2010,开发Windows7软件的绝配:Visual Studio 2010

    Win7之家( www.win7china.com):开发Windows7软件的绝配:Visual Studio 2010 这里介绍在Visual Studio 2010中,微软花了很大的力气来使得非 ...

  6. Win7 64位安装VS2010旗舰版出现错误...Microsoft Visual Studio 2010 64bitPrerequisites (x64)

    本文是为了备忘在Win7 64位系统中安装Visual Studio 2010旗舰版出现错误并多次得不到解决,最终寻得解决方法. 电脑装的是Win7 64位旗舰版系统,安装Visual Studio ...

  7. Visual Studio 2010 Ultimate测试体系结构

    VS2010测试概述<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&g ...

  8. ASP.NET 4 和 Visual Studio 2010 Web 开发概述

    声明:本文是ASP.NET 白皮书 ASP.NET 4 and Visual Studio 2010 Web Development Overview 的阅读摘要,只是本人的学习记录,并非完整翻译,仅 ...

  9. 小旋风asp iis_ASP 4-绕.NET 4(和Visual Studio 2010)Beta 1的旋风之旅

    小旋风asp iis Hey, we released Visual Studio 2010 Beta 1. JasonZ has a great post with piles of details ...

最新文章

  1. vsftpd学习笔记
  2. 浅谈MyBatis一级缓存
  3. UDO report generate DDIC table
  4. idea 设置jdk_IDEA开发小技巧~jdk问题
  5. 音视频开发(16)---海康IPC+NVR+EasyDarwin+EasyPusher+VLC实现Web实时播放RTSP视频
  6. java 中如何连接 oracle 数据库
  7. 标签打印软件如何设置单排标签纸尺寸
  8. Hadoop访问不了9870、8088
  9. 什么样的人适合当领导
  10. JFreeChart饼状图显示数字
  11. 长度最小的子数组(力扣209)
  12. 模拟角频率和数字角频率
  13. Linux网卡中断使单个CPU过载
  14. Dracula PRO 2021 零售版
  15. 二叉树的堂兄弟节点993
  16. 【Steam】关于上传游戏至Steam,Depot产生的问题
  17. org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type错误的解决办法
  18. 安卓手机控制小车(自己做成功了,有全套资料)
  19. C语言/gets()函数和scanf()函数关于字符串的输入
  20. 必修的思维导图教程五大进阶段

热门文章

  1. 买股票总是跌多涨少?买啥啥跌?试试“选股助手”吧
  2. Linux——MySQL视图
  3. 计算散列表查找成功和查找不成功的平均查找长度(利用线性探测法处理冲突)
  4. Element Tiptap Editor - 免费开源的 Vue 富文本编辑器,专门为搭配 Element UI 使用优化,使用很简单
  5. mysql sdo geometry_SDO_Geometry结构详细说明
  6. MySQL慢日志超时时间设置_Mysql的慢日志
  7. 微博java客户端开发教程_Java新浪微博客户端开发第四步
  8. 精细化研发提高冲压模具设计与制造的生产力
  9. 经典乐队1:Savage Garden
  10. docx 转 html api,将docX转换为自定义XML