【发布时间】:2012-07-04 14:02:57
【问题描述】:
我创建了一些Load Tests。我所有的负载测试都由一个单元测试组成。
我还创建了一个LoadTest Plug-in 并将其分配给我所有的负载测试。
每个单元测试都会使用以下代码更新我在 LoadTest 插件中创建的一些自定义性能计数器(更多详细信息here)。
插件代码:
private void m_loadTest_LoadTestStarting(object sender, System.EventArgs e)
{
CounterCreationDataCollection counters = new CounterCreationDataCollection();
counters.Add(new CounterCreationData("CustomCoumter", "Custom Coumter description", PerformanceCounterType.AverageCount64));
PerformanceCounterCategory.Create("CustomCounterCategory", "Custom Performance Counters", PerformanceCounterCategoryType.MultiInstance, counters);
}
单元测试代码:
[TestClass]
public class UnitTest1
{
PerformanceCounter customCounter;
[ClassInitialize]
public static void ClassInitialize(TestContext TestContext)
{
// Create the instances of the counters for the current test
customCounter= new PerformanceCounter("CustomCounterCategory", "CustomCoumter", "UnitTest1", false));
}
[TestMethod]
public void TestMethod1()
{
// ... Testing
customCounter.Incerement(time);
}
}
由于插件在Test Controller 中运行,因此在控制器运行的电脑中创建了自定义计数器类别。现在我正在使用许多Test Agents 在Test Rig 中运行我的负载测试。当单元测试在除测试控制器运行的计算机之外的其他计算机中执行时,计数器不会更新。我认为这是因为我的代码正在更新运行测试的 pc 中的计数器,而不是在控制器的 pc 中。
如何更新控制器电脑中的自定义计数器?我是否必须以不同的方式在单元测试中创建计数器的实例?
【问题讨论】:
标签: c# visual-studio-2010 unit-testing load-testing performancecounter