Is it possible to have a [OneTimeSetup] for ALL tests? Is it possible to have a [OneTimeSetup] for ALL tests? selenium selenium

Is it possible to have a [OneTimeSetup] for ALL tests?


OneTimeSetUpAttribute has two uses.

In the first, it marks a method in a test fixture that is run once before any other tests in that fixtrue. That's how you are using it, by inheriting from a base class. The OneTimeSetUp appears, thanks to inheritance, in each of your derived fixtures but it is still run multiple times, once for each fixture.

The second use is in a SetUpFixture. If you create a SetUpFixture in a particular namespace, it's OneTimeSetUp method will run once, before any other tests in that namespace. If you create the SetUpFixture outside of any namespace, then its OneTimeSetUp will run once before any tests in the assembly.

UPDATE: Someone suggested that the last sentence should say "outside of any namespace that contains a TestFixture." That would actually be incorrect. The SetUpFixture must be outside of any namespace to function at the assembly level. If there is a top-level namespace, which contains all test code, then you may also place a SetUpFixture there, with approximately the same effect. But if it's in a namespace with no tests under it, then it will never be run.

For more info about SetUpFixture, see the docs.