如何调用MoveDataTableCursor在Web测试插件通过有限的一组行的表? [英] How to call MoveDataTableCursor in a web test plugin to go through a limited set of rows in a table?

查看:384
本文介绍了如何调用MoveDataTableCursor在Web测试插件通过有限的一组行的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些困难,了解如何访问方法不要自动移动光标在一家网站的测试数据源。而在那里的文件似乎穷尽远。

I have some difficulties understanding how the access method "Do not move cursor automatically" works for a web test data source. And the documentation out there seems to be far from exhaustive.

首先,我们假设有一个简单的Web测试中,只有一个请求。它采用名为DS的数据源有一个名为步骤列表表,包含5行。

First of all, let's assume there is a simple web test with only one request. It uses a data source called DS with a table called StepList, that contains 5 rows.

对于表的访问方式设置为不自动移动光标和当前的测试设置有元数据源行的一个运行,在网络测试属性启用。该网站的测试不是一个负载测试的一部分。

The Access Method for the table is set to "Do not move cursor automatically" and the current test settings have "One run per data source row" enabled in the web test properties. The web test is not part of a load test.

在这些条件下,在测试运行5次,对于每一行,因此,它基本上自动移动光标。这是预期?

In these conditions, the test is run 5 times, for each row, so it basically moves the cursor automatically. Is this intended?

现在,到了实际的问题,这是这篇文章的主题。

Now, on to the practical question, which is the subject of this post.

我的步骤列表表中有(其中包括)标识列和StepId列。有问题的Web测试实际上是从另一个Web测试调用,它应该只为有StepId组在测试范围内表行中运行。

My StepList table above has, among others, an identity column and a StepId column. The web test in question is actually called from another web test, and it's supposed to run only for the table rows that have a StepId set in the test context.

Id  StepId
1   1
2   1
3   2
4   2
5   2

为了实现这个目标,我也跟着从<一个指引href="http://blogs.msdn.com/b/slumley/archive/2010/01/04/vsts-2010-feature-data-source-enhancements.aspx"相对=nofollow>这里,并写了一个Web测试插件的preWebTest方法看起来像这样:

In order to achieve this, I followed the guidelines from here and wrote a web test plugin with the PreWebTest method looking like this:

public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
    string stepId = string.Empty;

    if (e.WebTest.Context.ContainsKey(ContextParameterName))
    {
        stepId = e.WebTest.Context[ContextParameterName].ToString();
    }

    while (e.WebTest.Context["DS.StepList.StepId"].ToString() != stepId)
    {
        e.WebTest.MoveDataTableCursor("DS", "StepList");
    }
}

的code以上似乎对实施例表仅当stepId具有值2的正常工作。如果是1,则MoveDataTableCursor抛出WebTestEndOfDataException异常:没有更多的数据行与AccessMethod独特数据源表

The code above seems to work properly on the example table only if the stepId has the value "2". If it's "1", then MoveDataTableCursor throws WebTestEndOfDataException exception: "No more rows of data in a data source table with AccessMethod Unique".

我试图捕捉异常和停止Web测试,但是这并不工作,因为测试似乎永远不会结束。

I tried catching the exception and stopping the web test, but this doesn't work, as the test seems to never end.

什么是正确的方式来处理呢?

What is the proper way to deal with this?

感谢你。

推荐答案

要回答你的第一个问题:设置不自动移动光标适用于运行在负载测试仅,这是为什么光标仍然是一个网络测试,让你使用的是设置每个数据源行之一运行中自动移动。当然,后者的设置适用于网络测试只能运行。

To answer your first question: the setting "Do not move cursor automatically" applies to runs within a load test only, which is why the cursor still moves automatically during a web test where you are using the setting "One run per data source row". Of course, the latter setting applies to web test runs only.

你所得到的WebTestEndOfDataException的原因是:

The reason you are getting the WebTestEndOfDataException is:

  1. 的方式是由Visual Studio测试引擎中实现每个数据源行之一运行,包括一个事实,即只有一个数据指针所有五个试验;即光标的状态被记住所有5个测试之间。
  2. 在每次重复测试本身自动递增的数据光标。
  3. 您的插件的进步这套5次测试,在数据光标的一定的耗尽可用的行的5个试验完成之前。
  1. The way "One run per data source row" is implemented by the Visual Studio test engine includes the fact that there is only one data cursor for all five tests; i.e. the state of the cursor is remembered between all 5 tests.
  2. Each test iteration automatically increments the data cursor by itself.
  3. Your plugin advances the data cursor within this set of 5 tests, necessarily exhausting the available rows before the 5 tests have completed.

让你的测试工作最简单的方法是手动设置的迭代,而不是使用每个数据源行一次运行的数量。例如,只有两个数据中的有效行,所以设置迭代2。但是,这也是一个不错的解决方案,因为你将不得不手动计算行和更改值。

The simplest way to make your test work is to manually set the number of iterations instead of using "One run per data source row". For example, there are only two valid rows in your data, so set the iterations to 2. However, this is also a bad solution because you would have to manually count rows and change the value.

下一个最好的办法是改变你的WebTestPlugin使得它所做的就是检查DS.StepList.StepId的价值,做WebTest.Stop(),如果它不匹配所需的值。以此方式,不希望的迭代将立即终止。然而,他们仍然会浪费时间和增加视觉上的混乱。

The next best way is to change your WebTestPlugin such that all it does is check the value of DS.StepList.StepId and do WebTest.Stop() if it doesn't match the desired value. This way, the unwanted iterations will terminate immediately. However, they will still waste time and add visual clutter.

如果家长测试,始终要运行,而这仅仅是所谓的考试,应该被跳过,然后包了召唤WebTest的在字符串比较条件规则,检查DS.StepList.StepId对价值在stepId上下文参数,因此只要求孩子考试时StepId是正确的。

If the parent test should always run, and it is only the called test that should be skipped, then wrap the "Call to WebTest" in a "String Comparison" Conditional Rule that checks the value of DS.StepList.StepId against the stepId context parameter, thus only calling the child test when the StepId is correct.

这篇关于如何调用MoveDataTableCursor在Web测试插件通过有限的一组行的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆