junky_user
junky_user

Reputation: 385

Is it possible to to execute code befor all tests are run?

I am writing integration tests.Now, before tests are run I want to setup the database with initial data.For this, I have created a separate project, which is run before test project is executed(using MSBuild file).But, I want to merge the db setup code in testproject, and have it executed before any tests get executed.I am using MBunit 3.Is it possible?

Upvotes: 1

Views: 340

Answers (3)

Yann Trevin
Yann Trevin

Reputation: 3823

You can declare a class with the [AssemblyFixture] attribute; and a few methods into that class with the [FixtureSetUp] and [FixtureTearDown] attributes to define assembly-level setup and teardown methods.

[AssemblyFixture]
public class MyAssemblyFixture
{
   [FixtureSetUp]
   public void SetUp()
   {
      // Code to be run before any test fixture within the assembly are executed.
   }

   [FixtureTearDown]
   public void TearDown()
   {
      // Code to be run after all test fixture within the assembly are executed.
   }
}

In fact, the syntax is similar to what is usually done at test fixture level with the well-known [TestFixture], [SetUp], and [TearDown] attributes.

Upvotes: 1

Bolek Tekielski
Bolek Tekielski

Reputation: 1214

MBunit doesn't have excessive documentation, but quick googling gives this article from which I can tell that MBUnit has similar attributes to NUnit [SetUp] and [TearDown]. Methods decorated with those are executed before, and after each test respectively.

Upvotes: 0

Andrew
Andrew

Reputation: 5277

Generally test frameworks have method attributes to allow code to be executed before each test and after each test and before a test run and after a test run. I don't know the attributes for mbunit as I haven't used it.

Check out this link... I am sure mbunit would have attributes that are similar to nunit

http://blogs.msdn.com/nnaderi/archive/2007/02/01/mstest-vs-nunit-frameworks.aspx

Upvotes: 0

Related Questions