1

我编写了一个 Visual Studio (2008) Webtest 插件,需要在播放 ui 窗口中显示运行所需的时间。

我试过了:

e.WebTest.BeginTransaction("B2BValidate");

// then call my plugin

e.WebTest.EndTransaction("B2BValidate");

这确实将“B2BValidate”事务添加到播放窗口,但“总时间”列显示为 0.000 秒。我错过了什么?

-马特

4

2 回答 2

1

Visual Studio 中的事务期望包含一个请求——它们根本不能在没有请求之间直接内联的代码中工作。

您必须使用http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx之类的东西来启动和停止计时器,然后使用 WebTest 的 AddCommentToResult() 方法来显示webtest 结果查看器中经过的时间。

另一种选择是将您的 webtest 放入负载测试中,然后参考性能计数器:

  • LoadTestPlugin 中的 % 时间
  • % 规则时间
  • % WebTest 代码中的时间

当然,这只是给出比例而不是精确的时间数据。

于 2011-06-01T16:52:52.870 回答
-1

有一个需要实例化的 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");
     }
    }
于 2011-09-08T05:06:27.227 回答