Click here to Skip to main content
15,867,704 members
Articles / DevOps / Load Testing
Tip/Trick

Load Testing Error: There is already an active timer with the name '' passed to BeginTimer

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
3 Nov 2016CPOL 6.7K   1  
Fix for issue with TestContext.BeginTimer("TimerName");

Introduction

Without proper setup of a TestContext instance, this error can occur. For a quick overview, you need a full property for the TestContext instance, an you DO NOT need to set the value for it.

Information

If you create a property for TestContext and set the value in the AssemblyInitialize or ClassInitialize you are assigning your property to an instance of TestContext. If you do this in a load test, then every test reuses the same instance of that test context. If you use TestContext.BeginTimer("TimerName"); that instance of the Context adds a new Timer with that name, when the next load test runs it tries to add the same timer to the same TestContext and you get the error listed.

Proper Setup

C#
private TestContext _testContext;

public TestContext TestContext
{
    get { return _testContext; }
    set { _testContext = value; }
}

With this setup, the TestContext property will be set from the TestExecutioner and each load test will get its own TestContext.

Bad Setup

C#
private static TestContext _testContext;

[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{
    _testContext = testContext;
}

Usage of Timer

C#
TestContext.BeginTimer("DoWorkTimer");
DoWork();
TestContext.EndTimer("DoWorkTimer");

Points of Interest

Timers will show up in the test results under Scenario > Test Case Name > Transactions > Timer Name.

History

  • 3rd November, 2016: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I am currently an Automation Developer working on Coded UI Frameworks using Selenium, Load Testing Frameworks and Dynamic Data Frameworks for the prior mentioned testing systems. I maintain all of the software and hardware for our build, release and test systems, mostly using TFS, powershell and Hyper-V as well as building and maintaining Automated test systems.

Skills
SQL, Software Development, Microsoft SQL Server, Agile Methodologies
C#, JavaScript, HTML, C++, Markdown, XAML, XML
Quality Testing, Coded UI Testing, Selenium Testing, Load Testing
ALM, Team Foundation Server/VSO, Build Administration
Databases SQL/Oracle, Software and Hardware Installation/Maintenance
Troubleshooting, Project Management,
Solid State Electronics, Pulse Width Modulation, Metal Casting, Carbon Fiber Casting, Powder Coating.

Comments and Discussions

 
-- There are no messages in this forum --