AssemblyInitialize seems break unit test project in .net 6 (visual studio 2022)

364 Views Asked by At

I have a .net 4.8 unit test project and just migrated it to .net 6.

Although Test explorer shows all tests, when I try to run it in Visual Studio, it just doesn't run anything. What I found is that as soon as my unit test project contains this AssemblyInitialize attribute, Visual studio just won't run any of the tests.

[TestClass]
public class SetupAssemblyInitializer
{
    [AssemblyInitialize]
    public static void AssemblyInit(TestContext context)
    {
    }
}

This works fine as long as the project is in .net 4.8 and I didn't find any doc saying this attribute doesn't work in .net 6 any more. Is there any workaround or alternative to run some code only once in my Unit Test project?

If I decorate the method with [ClassInitialize], then the project will run without issue. However, this Attribute will not make the method run only once for all tests.

0

There are 0 best solutions below