ClassInitialize attribute in unit test based class not called

Solution 1:

When declaring ClassInitialize attribute on a method, the method has to be static, public, void and should take a single parameter of type TestContext.

If you're having also other method with the AssemblyInitialize attribute on the same unit test, the test will run but will skip on all test methods and will go directly to AssemblyCleanup or just quit.

Try the example on ClassInitialize attribute in MSDN.

Solution 2:

You can setup an assembly initialize method in your base class. Not quite the same as ClassInitialize, but it's a viable option. Source:The Workaround mentioned here.

[TestClass]
public abstract class TestBase
{
    [AssemblyInitializeAttribute]
    public static void Initialize(TestContext context)
    {
        // put your initialize code here
    }
}

You can also add a Cleanup method:

[AssemblyCleanup]
public static void Cleanup()
{
   //clean up stuff here
}