tags:

views:

71

answers:

3

Hi,

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?

A: 

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

Andrew
what i want is that - before any tests are executed, my db setup code must run once(not before every test)
junky_user
According to Google, MBunit supports [TestFixtureSetUp] attribute which marks method to be executed before every test in fixture.
Bolek Tekielski
A: 

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.

Bolek Tekielski
Well, there is pretty complete documentation of the entire API here: http://www.gallio.org/api/index.aspx
Yann Trevin
Only it's empty... see http://www.gallio.org/book/XHtml/ch03.html
Bolek Tekielski
You are right, the Gallio Book Project is still in a very early stage. But again, the API documentation is very complete and contains a lot of useful samples.
Yann Trevin
+1  A: 

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.

Yann Trevin