惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Martin Fowler
Martin Fowler
GbyAI
GbyAI
P
Palo Alto Networks Blog
N
Netflix TechBlog - Medium
C
Cisco Blogs
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
A
About on SuperTechFans
PCI Perspectives
PCI Perspectives
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
W
WeLiveSecurity
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
月光博客
月光博客
N
News | PayPal Newsroom
Microsoft Azure Blog
Microsoft Azure Blog
G
GRAHAM CLULEY
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
MongoDB | Blog
MongoDB | Blog
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Know Your Adversary
Know Your Adversary
博客园 - Franky
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
F
Full Disclosure
V
Vulnerabilities – Threatpost
V
Visual Studio Blog
Forbes - Security
Forbes - Security
Attack and Defense Labs
Attack and Defense Labs
MyScale Blog
MyScale Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Tor Project blog

博客园 - ξ箫音ξ

HP PCS 云监控大数据解决方案 HP “云图”GPU虚拟化工作站解决方案 如何使员工能力和收入相匹配? 基于微软Dryad分布式并行计算平台云技术的研究 得云计算者得天下 微软Windows Phone 7新特性详解 微软Share Point 2010企业应用解决方案 微软Windows Azure Platform技术解析 微软MSDN中文网络广播(Webcast)——Visual Studio 2010 & ALM应用实践系列课程预告(2011) 架构抉择:享用微软SQL云平台就像吃烤鸭 微软Visual Studio 2010架构设计功能应用 微软北京.NET俱乐部免费活动(2010年7月18日)–Visual Studio 2010 敏捷开发与云计算Azure WCF与Hprose在微软云计算平台Azure上的对决 深度解析:微软云计算平台的通信技术与应用开发 博客园新书《构筑敏捷的开发团队—VS2010实战兵法》已经出版 Visual Studio 2010 Ultimate中MSF过程模型设计 博客园添新书《Windows Powershell 2.0应用编程最佳实践》出版 Visual Studio 2010 Ultimate架构代码分析 Visual Studio 2010 Ultimate测试体系结构
在Visual Studio 2010中实现数据驱动Coded UI Tests
ξ箫音ξ · 2010-01-27 · via 博客园 - ξ箫音ξ

通常情况下我们要与不同的数据值一起重复一个测试。这个数据驱动Coded UI Test中非常容易的。在本例子中,我们创建了一个Coded UI Test以验证在计算器的两个数字增加。现在,让我们看看如何能够把一个简单的CodedUI Test转化为数据驱动测试。

  1、首先创建Coded UI Test Create the Coded UI Test)(请参考上一个实例);

然后创建数据集。Coded UI Test支持多个数据源。该数据集可以定义在一个CSV(逗号分隔值)文件,一个Excel工作表,XML文件,数据库表或TFS上的一个测试用例。在例子中,我们将使用与下面的数据CSV文件(TestData.csv)。

Add1

Add2

Sum

8

2

10

6

2

8

4

2

6

l   创建TestData.csv文件

 CSV”,是Comma Separated Value(逗号分隔值)的英文缩写,通常都是纯文本文件,可以用记事本打开。打开Excel,并复制上面数据到Excel中,选择菜单|文件|另存为,选择CSV格式,即可创建CSV文件。

对于每一段录制的操作,VSTS都可以把它抽象成一个方法,它会把这些操作以静态方法的形式存放在UIMap.Designer.cs的类里面。可以对这些方法做任意的修改,也可以把需要输入的方法增加一个输入的参数。

2、添加数据源到Coded UI TestAdd the Data Source binding in Coded UI Test)。

1)打开VS菜单|Test View-> Windows -> Test View,如图1所示。

图1  Coded UI Test属性中创建数据连接

3)通过上面操作,打开新的数据源向导界面,创建数据源。选择CSV File>单击Next,如图2所示。

图2  新建数据源向导

 4)选择步骤一建立的TestData.csv文件,测试数据源向导预览,单击Finish”,该csv数据文件加入到该项目中。如图3所示。

图3  新建数据源向导文件数据预览

   新文件数据文件属性自动添加到Coded UI TestCodedUITest1.cs文件中。文件属性如下:

[DeploymentItem("TestProject\\TestData.csv"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestData.csv", "TestData#csv", DataAccessMethod.Sequential), TestMethod]

3、在Coded UI Test中使用数据。打开Coded UI Test文件(CodedUITest1.cs)添加代码片段。

   代码片段如下:

this.UIMap.计算器Window.Item8Window.Item8Button.SearchProperties[WinProperties.Button.Name] =

TestContext.DataRow["Add1"].ToString();

    这样的修改后,当运行测试的时候会第一次运行单击按钮(计算器)动作。程序员会搜索CSV file,在其中挑选适合的值。

注意:测试的对象必须包含被处理的所有数据,并且数据源必须存在。可以参考的列名(例如:Add1”)。

同样的,添加下面代码片段,它修改了第二次点击计算器。

代码片段如下:

this.UIMap.计算器Window.Item2Window.Item2Button.SearchProperties[WinProperties.Button.Name] =

TestContext.DataRow["Add2"].ToString();

   新增this.UIMap.AssertSum()方法,调用下面的代码:

this.UIMap.AssertSumExpectedValues.ItemEditText = TestContext.DataRow["Sum"].ToString();

现在可以进行验证,从CSV文件获取数据进行自动化测试结果。

4运行数据驱动测试。单击右键弹出菜单,选择Run Tests”,运行Coded UI Test方法进行自动化测试。如图4所示。

 运行数据驱动测试

该测试运行时候将执行3次(如需要多次迭代,根据数据源的数据行)。测试结果将显示每个迭代的细节。如图5所示。

图5  数据驱动测试结果信息

至此,我们已经看到测试实例,了解了如何创建一个数据驱动测试。VSTS自动生成的UIMap.Designer.csUIMap类,里面的方法都可以重用,稍加修改就能达到比较好的测试效果(同时也需要对这个类的方法进行整理)。

如果测试用例是MTLM工具创建,还有一个更简单的方法,使其数据驱动。有关MTLM结合的工作流程将在以后中的介绍。