c# - 如果发生错误,则中止网络测试

标签 c# visual-studio-2010 mstest load-testing webtest

使用 VS2010 的负载测试功能和记录的网络测试。

我在记录的网络测试中遇到级联错误问题。也就是说,如果一个请求失败,其他几个请求也会失败。这会在日志中造成很多困惑,因为通常只有第一个错误是相关的。

有没有办法让失败的验证规则在失败时终止网络测试,而不运行其余的请求?

(要明确的是,我仍然想继续进行一般的负载测试,只是停止该特定测试用例的特定迭代)

下面是一些示例代码,演示了我正在尝试做的事情:

using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace TestPlugInLibrary
{
    [DisplayName("My Validation Plugin")]
    [Description("Fails if the URL contains the string 'faq'.")]
    public class MyValidationPlugin : ValidationRule
    {
        public override void Validate(object sender, ValidationEventArgs e)
        {
            if (e.Response.ResponseUri.AbsoluteUri.Contains("faq"))
            {
                e.IsValid = false;
                // Want this to terminate the running test as well.
                // Tried throwing an exception here, but that didn't do it.
            }
            else
            {
                e.IsValid = true;
            }
        }
    }
}

最佳答案

我找到了一个很好的解决方案。有个博客here详细说明了它,但简短的版本是使用 e.WebTest.Stop()。这将中止当前测试的当前迭代,同时根据需要保持运行的其余部分完好无损。

关于c# - 如果发生错误,则中止网络测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14468173/

相关文章:

c# - 为什么我的公共(public)类不能扩展内部类?

.net - 如果Unity不在GAC中,VS如何知道在添加引用中显示它?

c# - wpf(离线)应用程序 c# 的更新问题

c# - 如何强制 VS 2010 跳过未更改的项目的 "builds"?

dll - 为什么 MSTest 不复制引用的项目库?

c# - 用于单元测试的 Global.asax?

c# - 在 Windows 窗体应用程序中实现键盘快捷键的最佳方式?

c# - 如何同时(并行)使用多个客户端调用 WCF webservice

c# - 总可用空间检测不适用于大型硬盘驱动器?

visual-studio - VSTS + Visual Studio 测试 : Add additional logs to test output