VSTS 提供了一个丰富、强大的工具平台,融合了软件开发领域的各个角色,涵
盖软件开发生命周期的各个阶段,包括设计,开发,测试,管理,而这一整套构
件的融会贯通,让它可以有效地改善软件开发过程中各个阶段的弊端,提高团队
之间不同的角色的协调能力,提高工作效率。
本文就简单介绍一下如何利用 VSTS 给一个网站做压力测试。
1 建立一个测试项目,起名 MyTest
2 建立一个 Web Test
点击 Web Test...
IE 马上就会弹出一个窗口,这样录制脚本工作就可以开始了。
3 在 IE 里输入要测试的网站地址: 比如
http://localhost/WebSite/Default.aspx
4 对该网站做一些操作, 此时 VSTS 会纪录下你的这些操作,用以作为压力测试
的场景。
5 录制脚本毕,点击 "STOP"
6 点击生成代码,可以看到刚才录制的类似如下的代码:
//-------------------------------------------------------------------
-----------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//-------------------------------------------------------------------
-----------
namespace MyTest
{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.WebTesting;
using Microsoft.VisualStudio.TestTools.WebTesting.Rules;
public class WebTest1Coded : WebTest
{
public WebTest1Coded()
{
this.PreAuthenticate = true;
}
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest request1 = new
WebTestRequest("http://localhost/WebSite/Default.aspx");
request1.ThinkTime = 1688;
ExtractHiddenFields rule1 = new ExtractHiddenFields();
rule1.ContextParameterName = "1";
request1.ExtractValues += new
EventHandler<ExtractionEventArgs>(rule1.Extract);
yield return request1;
WebTestRequest request2 = new
WebTestRequest("http://localhost/WebSite/Default.aspx");
request2.ThinkTime = 2;
request2.Method = "POST";
FormPostHttpBody request2Body = new FormPostHttpBody();
request2Body.FormPostParameters.Add("__VIEWSTATE",
this.Context["$HIDDEN1.__VIEWSTATE"].ToString());
request2Body.FormPostParameters.Add("Button1", "Go to Test Page");
request2Body.FormPostParameters.Add("__VIEWSTATEENCRYPTED",
this.Context["$HIDDEN1.__VIEWSTATEENCRYPTED"].ToString());