简体   繁体   English

visual studio web测试错误处理

[英]visual studio web test error handling

I'm using Visual Studio Ultimate 2013 and have a load test that uses a web test with a number of request and web test plugins. 我正在使用Visual Studio Ultimate 2013并进行负载测试,该测试使用带有大量请求和Web测试插件的Web测试。

In my PostRequest plugin, I'm checking the http status code of the response and am flagging an error in a WebTest.Context parameter, when a hhtp code of over 400 is returned. 在我的PostRequest插件中,我正在检查响应的http状态代码,并在返回超过400的hhtp代码时标记WebTest.Context参数中的错误。 What I want to do is pick this up in the PostTransaction WebTest plugin and update a database table. 我想要做的是在PostTransaction WebTest插件中选择它并更新数据库表。 The problem is, that the test aborts when the framework detects the error and the PostTransaction plugin isn't called. 问题是,当框架检测到错误并且未调用PostTransaction插件时,测试将中止。

I've added a PostWebTest plugin, that I thought would be called when the test iteration aborted, but it's never hitting this when a request fails. 我添加了一个PostWebTest插件,我认为在测试迭代中止时会调用它,但是当请求失败时它永远不会发生这种情况。 It does hit it if the test is successful. 如果测试成功,它确实会成功。 What am I missing? 我错过了什么?

public override void PostRequest(object sender, PostRequestEventArgs e)
{
    ...
    statusCode = e.Response.StatusCode.GetHashCode();
    If (statusCode > 400)
    {
        e.WebTest.Context["TransactionFailCount"] = 1;
    }
}

public override void PostTransaction(object sender, PostTransactionEventArgs e)
{
    int transactionFailCount = Convert.ToInt32(e.WebTest.Context["TransactionFailCount"]);
    if (transactionFailCount > 0)
        failCount = 1;
    else
        passCount = 1;
    ...
    base.PostTransaction(sender, e);

 }

 public override void PostWebTest(object sender, PostWebTestEventArgs e)
 {
     base.PostWebTest(sender, e);
 }

Thanks 谢谢

A Web Performance Test (WPT) will continue to execute after an error is detected unless the Stop on error property of the test is true . 检测到错误后,Web性能测试(WPT)将继续执行,除非测试的Stop on error属性为true It is possible that some aspects of a the handling of a request are not performed after an error, but I have not seen any such cases. 在发生错误之后,可能不会执行处理请求的某些方面,但我没有看到任何此类情况。

Be careful of terminology. 小心术语。 WPTs use "transactions" as a way of grouping several requests. WPT使用“交易”作为分组多个请求的方式。 The context (right click) menu of a request has an "Add transaction" entry that selects a range of items in the test to be included in that transaction. 请求的上下文(右键单击)菜单具有“添加事务”条目,该条目选择要包括在该事务中的测试中的一系列项目。 Perhaps you should be using the PostRequest or PostPage plugins rather than PostTransaction . 也许您应该使用PostRequestPostPage插件而不是PostTransaction

I recommend that you do some experiments with a simple two or three request WPT plus some simple plugins that just announce that they have been called. 我建议您使用简单的两个或三个请求WPT以及一些只是宣布它们已被调用的简单插件进行一些实验。 For example 例如

public override void PostRequest(object sender, PostRequestEventArgs e)
{
    e.WebTest.AddCommentToResult("PostRequest called for url " + e.Request.Url);
}

Additionally, there is a good explanation of how and when plugins are called in pages 32 to 44 of the Visual Studio Performance Testing Quick Reference Guide from Codeplex. 此外,还有一个很好的解释,说明在Codeplex的Visual Studio性能测试快速参考指南的第32到44页中如何以及何时调用插件。

The statement statusCode = e.Response.StatusCode.GetHashCode(); 语句statusCode = e.Response.StatusCode.GetHashCode(); is strange. 很奇怪 The value of e.Response.StatusCode is an enum , it integer value can be obtained by casting. e.Response.StatusCode的值是一个enum ,它的整数值可以通过强制转换获得。 The GetHashCode method is not intended to get the numeric value of an enum . GetHashCode方法不用于获取enum的数值。 The statement would be better as statusCode = (int)e.Response.StatusCode; 语句会更好,因为statusCode = (int)e.Response.StatusCode; or the assign and test (note that if is used for conditionals in C#, not If ) might be better as 或者分配和测试(注意, if用于C#中的条件,而不是If )可能会更好

statusCode = e.Response.StatusCode;
if ( e.Response.StatusCode >= System.Net.HttpStatusCode.BadRequest ) { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM