Max Banaev
Max Banaev

Reputation: 926

Can I perform action before/after all tests

I know, that in Coded UI there are two methods (MyTestInitialize and MyTestCleanup) which can perform action before and after each tests. I need add some action which launch before and after all tests. For example, if you familiar with rspec there are two methods before() and after(), which take parameter :each (will call before/after each tests) or :all (will call before/after all test).

Upvotes: 1

Views: 174

Answers (1)

Ryan Cox
Ryan Cox

Reputation: 958

Create your methods with the [ClassInitialize] and [ClassCleanup] attributes as necessary. This should be within your Test Class. Example:

[CodedUITest]
public class MyTestClass
{
    [ClassInitialize]
    public void DoSomethingFirst()
    {
        // your code here that will run at the beginning of each test run.
    }

    [TestInitialize]
    public void RunBeforeEachTest()
    {
        // your test initialization here
    }

    [TestMethod]
    public void MyTestMethod()
    {
    }
}

And you would do the same for your [TestCleanup] and [ClassCleanup].

More on this attribute can be found here.

Upvotes: 2

Related Questions