When a data source attribute (Column, Row, FileData, SqlData, ResourceData,
Linear, Factory, etc...) is applied to a generic type parameter, a
constructor parameter, a field, or a property of a fixture, then we get a
data-driven fixture. Likewise, a data source may be applied to a method, a
generic method parameter, or a method parameter to get a data-driven test.
Data sources can also be declared in a containing fixture and bound to using
a [Bind] attribute. Automatic bindings exist in some cases.
What this means for a fixture, is that you will get multiple instances of
the fixture. The fixture's [TestFixtureSetUp] methods will run each time
for each combination of values that are bound to fixture parameters (after
they have been set).
I don't currently have a feature for binding values to a fixture via
methods, but it would be a straight-forward extension of the framework.
[Initializer]
[Column("1", "2", "3")]
public void ApplyConfiguration(string paramValue)
I just made up the [Initializer] attribute on the spot.
Similar behavior is already supported at the constructor level.
[TestFixture]
public class Fixture
{
public Fixture([Column("1", "2", "3")] string paramValue)
{
}
}
Jeff.
_____
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Yanick Masse
Sent: Monday, December 17, 2007 11:59 AM
To: [email protected]
Subject: MbUnit Re: Multi Setup Fixture
Will it be possible to assign the Column attribute to a method instead
assigning it to a public properties? My example was a little bit dumb but
in my real case, the configuration that I need to apply need a couple line
of codes.
So, would it be possible to do something like that:
[Column("1", "2", "3")]
public void ApplyConfiguration(string paramValue)
{
if (paramValue == "1")
DoSomething();
else if (paramValue == "2")
DoSomethingElse();
else if (paramValue == "3")
AnotherCall();
}
On Dec 17, 2007 2:45 PM, Jeff Brown < [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:
My suggestion would be to hold off until MbUnit v3 alpha 2 is released (in a
couple weeks we hope) and then to use the new data-driven testing features
like this:
[TestFixture]
public class MyFixture
{
[Column("1", "2", "3")]
// equivalent to: [Row("1"), Row("2"), Row("3")]
public string param;
[Test]
[Row("a", "z")]
[Row("b", "y")]
public void Test(string x, string y)
{
}
}
The Test method will be run 6 times with:
param="1", x="a", y="z"
param="1", x="b", y="y"
param="2", x="b", y="y"
param="2", x="b", y="y"
param="3", x="b", y="y"
param="3", x="b", y="y"
Jeff.
-----Original Message-----
From: [email protected] <mailto:[email protected]>
[mailto:[EMAIL PROTECTED] On
Behalf Of Yanick Masse
Sent: Monday, December 17, 2007 9:55 AM
To: MbUnit.User
Subject: MbUnit Multi Setup Fixture
Hi,
I would like to develop a special fixture in which it would be a mix
of the RowTestAttribute and TestFixtureSetUpAttribute. Multiple
"MultiSetUp" attributes could be applied to a SetUp function. Tests
functions decorated with TestAttributes would be called once for each
occurence of the MultiSetUp function.
Here is a little example of this special fixture.
[MultiSetUpFixture]
public class TestMultiSetUpFixture
{
[MultiSetUp("1")]
[MultiSetUp("2")]
[MultiSetUp("3")]
public void MultiSetUp(string param1)
{
// Do some setup using param1...
}
[Test]
public void Test1()
{
}
[Test]
public void Test2()
{
}
[MultiSetUpTearDown]
public void MultiSetUpTearDown()
{
}
}
In this example, the methods would be invoked in the following order when
running the test:
MultiSetUp("1")
Test1()
Test2()
MultiSetUpTearDown()
MultiSetUp("2")
Test1()
Test2()
MultiSetUpTearDown()
MultiSetUp("3")
Test1()
Test2()
MultiSetUpTearDown()
Does someone have any hints to help me implement this special fixture or
another suggestions? My goal is to run my tests on multiple configuration
but I don't want my configuration to be applied for each test method.
--
--------------------------------------
Yanick Masse
[EMAIL PROTECTED]
514-813-3635
www.myspace.com/hefters
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---