TheX
TheX

Reputation: 327

AssemblyInitialize method doesnt run before tests

I am using MsTest V2 framewrok for my tests. I have Test automation framework (TAF) project and project with tests. Tests project inherited from TAF and contains only tests. In TAF i have a class which contains method which should run before all tests but it doesnt work at all. By the way BeforeTest method works fine.

public class TestBase
{
    [AssemblyInitialize]
    public static void BeforeClass(TestContext tc)
    {
        Console.WriteLine("Before all tests");
    }
    [TestInitialize]
    public void BeforeTest()
    {
        Console.WriteLine("Before each test");
    }
}


[TestClass]
public class FirstTest : TestBase
{
    [TestMethod]
    public void FailedTest()
    {
        Assert.IsTrue(false,"ASDASDASD");
    }
}

If I put "AssemblyInitialize" method to tests projects then it work.

What am I doing wrong?

Upvotes: 12

Views: 11485

Answers (1)

Francesco Bonizzi
Francesco Bonizzi

Reputation: 5302

Just put [TestClass] onto your TestBase:

[TestClass]
public class TestBase
{
    [AssemblyInitialize]
    public static void BeforeClass(TestContext tc)
    {
       Console.WriteLine("Before all tests");
    }

    [TestInitialize]
    public void BeforeTest()
    {
           Console.WriteLine("Before each test");
    }
}

Upvotes: 17

Related Questions