获取将要启动并引发了 PreWebTest 事件的 WebTest 对象。
命名空间:  Microsoft.VisualStudio.TestTools.WebTesting
程序集:  Microsoft.VisualStudio.QualityTools.WebTestFramework(在 Microsoft.VisualStudio.QualityTools.WebTestFramework.dll 中)
语法
声明
Public ReadOnly Property WebTest As WebTest
    Get
public WebTest WebTest { get; }
public:
property WebTest^ WebTest {
    WebTest^ get ();
}
member WebTest : WebTest
function get WebTest () : WebTest
属性值
类型:Microsoft.VisualStudio.TestTools.WebTesting.WebTest
一个 WebTest 对象。
示例
以下示例显示了 Web 性能测试插件,此插件在运行 Web 性能测试之前将随机数添加到上下文。 在 Web 性能测试运行之后,此插件显示最后的 WebTestResponse 的长度。
请注意此属性如何提供对 WebTest 的引用。
using System;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Windows.Forms;
namespace WebTestPluginNamespace
{
    public class MyWebTestPlugin : WebTestPlugin
    {
        public static string NewRandomNumberString(int size)
        {
            byte[] buffer = new byte[size];
            // Seed using system time
            Random random = new Random(unchecked((int)DateTime.Now.Ticks));
            random.NextBytes(buffer);
            return BitConverter.ToInt32(buffer, 0).ToString();
        }
        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {
            e.WebTest.Context["RandNum"] = NewRandomNumberString(4);
        }
        public override void PostWebTest(object sender, PostWebTestEventArgs e)
        {
            MessageBox.Show(e.WebTest.LastResponse.ContentLength.ToString());
        }
    }
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。