我编写了一个 Visual Studio (2008) Webtest 插件,需要在播放 ui 窗口中显示运行所需的时间。
我试过了:
e.WebTest.BeginTransaction("B2BValidate");
// then call my plugin
e.WebTest.EndTransaction("B2BValidate");
这确实将“B2BValidate”事务添加到播放窗口,但“总时间”列显示为 0.000 秒。我错过了什么?
-马特
我编写了一个 Visual Studio (2008) Webtest 插件,需要在播放 ui 窗口中显示运行所需的时间。
我试过了:
e.WebTest.BeginTransaction("B2BValidate");
// then call my plugin
e.WebTest.EndTransaction("B2BValidate");
这确实将“B2BValidate”事务添加到播放窗口,但“总时间”列显示为 0.000 秒。我错过了什么?
-马特
Visual Studio 中的事务期望包含一个请求——它们根本不能在没有请求之间直接内联的代码中工作。
您必须使用http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx之类的东西来启动和停止计时器,然后使用 WebTest 的 AddCommentToResult() 方法来显示webtest 结果查看器中经过的时间。
另一种选择是将您的 webtest 放入负载测试中,然后参考性能计数器:
当然,这只是给出比例而不是精确的时间数据。
有一个需要实例化的 TransactionTimer 类,并定义了计时器的请求范围。
public class DynamicTransactionTimer : WebTestRequestPlugin
{
public override void PreRequest(object sender, PreRequestEventArgs e)
{
TransactionTimer t = new TransactionTimer();
t.Name = "trx3";
t.Items.Add(e.Request);
e.WebTest.BeginTransaction("trx3");
}
public override void PostRequest(object sender, PostRequestEventArgs e)
{
e.WebTest.EndTransaction("trx3");
}
}