Getting error (MyClassName).MyClassInitialize has wrong signature. The method must be static, public, does not return a value and should take a single parameter of type TestContext.

John Mann 41 Reputation points
2022-11-25T18:27:45.147+00:00

I'm running in VS 2022 with .NET Framework 4.8
I'm referencing NuGet packages MsTest.TestAdapter and MsTest.TestFramework 2.2.10.

I'm getting this error for a lot of tests
(MyClassName).MyClassInitialize has wrong signature. The method must be static, public, does not return a value and should take a single parameter of type TestContext.

The class does have the correct signature:

    [ClassInitialize()]  
    public static void MyClassInitialize(TestContext context)  
    {  

...
}

It runs ok locally but when it runs in the build many tests fail with this error. Any ideas what might be causing this?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,582 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
336 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,366 Reputation points
    2022-11-25T19:34:29.507+00:00

    See my template project, the code for test are broken down to use a partial class here and the main test class uses this class.

    264327-test.png


  2. John Mann 41 Reputation points
    2022-11-29T10:14:16.057+00:00

    This isn't really an answer but it is how I fixed the problem - I rewote the tests in xUnit and used IClassFixture<T> instead of ClassInitialize.

    0 comments No comments

  3. Jude Dennis 0 Reputation points
    2023-04-26T14:10:59.5866667+00:00

    I got this error when adding a new test class file to an existing unit test project. It was a copy/paste of an existing one and the original still works. The new one though, gets this error. Even though it is identical to what the error says it should be... So, the best way to resolve this is to use a different unit test library? Way to go Microsoft.

    0 comments No comments