Visual Studio 负载测试 - 使用哪个 post Web 测试事件处理程序
Visual Studio Load Testing - Which post web test event handler to use
我的测试 class 中有一个静态对象,它通过负载测试插件填充,需要使用从每个请求返回的数据进行更新。除了响应数据之外,我唯一需要的信息是发送请求时使用的原始 webtest 上下文中的 WebTestUserId。
我似乎可以通过验证规则来做到这一点:
ValidationClass: ValidationRule
{
public override void Validate(object sender, ValidationEventArgs e)
{
JObject responseBody = JObject.Parse(e.Response.BodyString);
int webTestUserId= ((TheTestClass)sender).Context.WebTestUserId;
// update some static field in the test class
}
}
不过,我确实看到了其他可能有效的选项,但找不到有关差异或推荐方法的文档。我看到事件处理程序:
WebTest.PostWebTest,
WebTest.ValidateResponse,
WebTest.ValidateResponseOnPageComplete, and
LoadTest.TestFinished (would be used in the plugin)
我不能 post 超过 2 个链接,但可以在 WebTest class 上找到两个未超链接的事件处理程序。
在什么情况下应该使用这些中的每一个?
Validation rules are intended to check that the test is running correctly and to set a failure status and failure message, if appropriate. For your purposes it may be better to use a plugin to retrieve and save the wanted data. If the data comes from a specific request then use the PostRequest
method of a WebTestRequestPlugin
. If data needs to be collected from all requests then use the PostRequest
method of a WebTestPlugin
.
不同插件类型(以及提取和验证规则)的功能之间存在重叠。从 Microsoft 文档中应该可以清楚地了解它们的用途。 Web 测试项仅从显式调用它们的 Web 测试中调用。负载测试插件的 TestStarting
和 TestFinished
方法会为作为负载测试的一部分执行的所有测试调用。
题中代码的最终赋值可以简化为int webTestUserId = e.WebTest.Context.WebTestUserId;
。这适用于验证规则和插件。
我的测试 class 中有一个静态对象,它通过负载测试插件填充,需要使用从每个请求返回的数据进行更新。除了响应数据之外,我唯一需要的信息是发送请求时使用的原始 webtest 上下文中的 WebTestUserId。
我似乎可以通过验证规则来做到这一点:
ValidationClass: ValidationRule
{
public override void Validate(object sender, ValidationEventArgs e)
{
JObject responseBody = JObject.Parse(e.Response.BodyString);
int webTestUserId= ((TheTestClass)sender).Context.WebTestUserId;
// update some static field in the test class
}
}
不过,我确实看到了其他可能有效的选项,但找不到有关差异或推荐方法的文档。我看到事件处理程序:
WebTest.PostWebTest, WebTest.ValidateResponse, WebTest.ValidateResponseOnPageComplete, and LoadTest.TestFinished (would be used in the plugin)
我不能 post 超过 2 个链接,但可以在 WebTest class 上找到两个未超链接的事件处理程序。
在什么情况下应该使用这些中的每一个?
Validation rules are intended to check that the test is running correctly and to set a failure status and failure message, if appropriate. For your purposes it may be better to use a plugin to retrieve and save the wanted data. If the data comes from a specific request then use the PostRequest
method of a WebTestRequestPlugin
. If data needs to be collected from all requests then use the PostRequest
method of a WebTestPlugin
.
不同插件类型(以及提取和验证规则)的功能之间存在重叠。从 Microsoft 文档中应该可以清楚地了解它们的用途。 Web 测试项仅从显式调用它们的 Web 测试中调用。负载测试插件的 TestStarting
和 TestFinished
方法会为作为负载测试的一部分执行的所有测试调用。
题中代码的最终赋值可以简化为int webTestUserId = e.WebTest.Context.WebTestUserId;
。这适用于验证规则和插件。