Visual studio 2013 Visual Studio负载测试-每次都有唯一的数据

Visual studio 2013 Visual Studio负载测试-每次都有唯一的数据,visual-studio-2013,load-testing,Visual Studio 2013,Load Testing,我正在使用Visual Studio Ultimate 2013进行一些负载测试。我有一些测试数据附加到我的web测试中,有10000行唯一的数据,我在另一个项目中也有一个web测试插件,我已经引用了它。在网络测试中 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.VisualStu

我正在使用Visual Studio Ultimate 2013进行一些负载测试。我有一些测试数据附加到我的web测试中,有10000行唯一的数据,我在另一个项目中也有一个web测试插件,我已经引用了它。在网络测试中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.QualityTools.WebTestFramework;
using Microsoft.VisualStudio.TestTools.WebTesting;



namespace VUControl
{
    public class VUControl : WebTestPlugin
    {
        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {
            base.PreWebTest(sender, e);
            e.WebTest.MoveDataTableCursor("testdata", "strictly#csv", e.WebTest.Context.WebTestUserId);
        }
    }
}
我已将源表属性设置为“不自动移动光标”

负载测试设置为在云上运行,运行5分钟,有500个用户

在运行测试时,我成功地完成了大约9500个测试,但我只得到了数据库中生成的大约10组独特的数据

我正在测试的页面本质上是网站上的注册页面


有人能告诉我为什么我只看到10个随机选择的数据出现吗?

我猜你有10个load Generator?或者最多10个线程

在我看来,真正的问题是MoveDataTableCursor()方法在独立的webtest中工作,但在负载测试中包含相同的web或API测试时就不工作了。您可以通过为数据集实现行计数来解决此问题,如下所示:

// datasetRowNumber is a pointer to the row number of an in-memory copy of the dataset. Each agent has a copy of the dataset.
static int datasetRowNumber; 
public override void PreWebTest(object sender, PreWebTestEventArgs e)
    {
        int totalAgentCount = e.WebTest.Context.AgentCount; // Used in a modulus operation to skip rows in the dataset
        int agentID = e.WebTest.Context.AgentId; //Used in conjunction with totalAgentCount in the modulus operation 


        while ((datasetRowNumber++ % totalAgentCount) != (e.WebTest.Context.AgentId - 1))
        {
           // We have incremented datasetRowNumber in the line above. 
           // Here is where we will use it to point to the new row. 
            e.WebTest.MoveDataTableCursor(DSName, tableName, datasetRowNumber);
        }

            string dataValue = e.WebTest.Context["DataSource1.SampleData.PRNCode"].ToString();

        // Logging. Comment this out during a load test!
        // writer.WriteToLog("Value=" + dataValue + ", TotalAgentCount=" + e.WebTest.Context.AgentCount + ", AgentID=" + e.WebTest.Context.AgentId + ", Iteration=" + iteration);

    }
上述代码是以下博客中代码的实现: . Sean Lumley的“访问方法描述”对于web测试非常有用,但是当放入负载测试时,MoveDataTableCursor()方法并不能像预期的那样工作

上面的代码使用MoveDataTableCursor()的重载 描述的微妙之处


如果没有DataSetRownNumber变量,Slumley的代码不会在负载测试中提前游标;在Lumley的版本中,光标前进仅在独立的webtest中有效

除了在web测试项目的引用中添加插件项目外,您还必须调用插件-使用“添加web测试插件…”。仅仅因为web测试运行时没有报告任何错误并不意味着单个测试可以工作。建议在测试中的几个请求中添加验证规则,以检查第一个响应中是否有“输入用户名和密码”之类的词。然后检查后续响应中是否有“登录成功”、“创建了数据库记录”、“注销成功”之类的词。我会继续讨论这个问题。与此同时,你有机会看看这个吗