AssemblyInitialize in derived class

I had the same problem when I didn't mark the test base class with the [TestClass] attribute.


Try to implement a separate class without inheritance in your Test Project :

[TestClass]
public static class YourClass
{
    [AssemblyInitialize]
    public static void AssemblyInit(TestContext context)
    {
       //DoSomething
    }
}

It should be called.


This is happening because the Assembly is never initialized if you don't run tests from it. A solution I can give (maybe a fool one) is to use the AssemblyInitialize on the other assemblies and call the base AssemblyInitialize

In a TestProject which contains tests add the following code:

[TestClass]
public class UnitTest1
{
    [AssemblyInitialize]
    public static void AssemblyInitialize(TestContext testContext)
    {
        // call the base AssemblyInitialize
        BaseTestProject.BaseTest.AssemblyInitialize(testContext);
    }

    public TestContext TestContext { get; set; }
}

Tags:

C#

Mstest