RobVious
RobVious

Reputation: 12925

How to get Setup and Teardown working per-Fixture?

I have the following:

    [TestFixture]
    public class SmokeTest : BaseTest
    {
        [Test(Description = "Should Do This")]
        public void ShouldDoThis()
        {
            //Tests,Assertions,etc
        }

        [Test(Description = "Should Do That")]
        public void ShouldDoThat()
        {
            //Tests,Assertions,etc
        }

    }

With BaseTest defined as:

   [TestFixture]
   public class BaseTest
   {
    [TestFixtureSetUp]
    public void SetUp()
    {
        // set up browsers
    }
    [TearDown]
    public void Dispose()
    {
        // dispose browsers
    }
   }

The goal is to have the selenium browsers' drivers created once per testFixture (// set up browsers), then at the end of the Fixture, torn down. Right now the browsers are being killed after the first test though, and the second test fails with some "Unable to connect to the remote server" error.

I'd like to target the first problem here - why is the TearDown method being called after the first test?

Upvotes: 5

Views: 2300

Answers (1)

adrianbanks
adrianbanks

Reputation: 83014

You need to use the TestFixtureTearDown attribute instead of the TearDown attribute in your base test. The TestFixtureTearDown attribute will cause the method to be run only once at the end of all of the tests in the fixture.

Upvotes: 6

Related Questions