Fails to execute classes with ClassInitialize method present

Viewed 4904

I face an awkward situation - all test classes that have [ClassInitialize] method present fail to execute all test methods inside.

Example:

[TestClass]
public class ChargeAccountServiceTests
{
    private static PrivateType ChargeAccountService_Accessor;

    [ClassInitialize]
    public static void InitializeClass(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext context)
    {
         ChargeAccountService_Accessor = new PrivateType(typeof(ChargeAccountService));
    }

    [TestMethod]
    public void TestFixOMRHappySHA()
    {
          //TEST LOGIC
    }
}

Causes test agent to throw following exception:

Test Name:  TestFixOMRHappySHA
Test FullName:  ChargeAccountServiceTests.TestFixOMRHappySHA
Test Source:    \ChargeAccountServiceTests.cs : line 22
Test Outcome:   Failed
Test Duration:  0:00:00

Result Message:

Method ChargeAccountServiceTests.InitializeClass has wrong signature. Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.

This test has been working few days ago. Test project target is .NET 3.5

3 Answers

I had the same error but for [AssemblyInitialize] not [ClassInitialize].

Removing the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework and re-adding v10.0.0.0 fixed the problem for me.

It turned out my different test projects were referencing different versions, and making them all consistently point to 10.0.0.0 fixed the problem.

Related