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
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
private static TestContext _testContext;
[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{
_testContext = testContext;
}
Usage of Timer
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
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.