There are several options here.  Here are two of them:

1. Put the row or factory attribute on the constructor.

2. Put the attributes instead on one or more writable properties or fields of 
the class.

(Fields, properties, constructor parameters and generic type parameters can 
also be bound positionally or by name using a data source  attribute on the 
class level.  This is useful if you want to use multiple columns of values from 
the same source.)

However it is not possible to parameterize setup.  I think you'll find the 
alternatives more than compensate.

Jeff.
-----Original Message-----
From: "[email protected]" <[email protected]>
Date: Wednesday, Jan 21, 2009 12:28 pm
Subject: MbUnit Re: mixture of TestSuite and DataDriven testing
To: "MbUnit.User" <[email protected]>Reply-To: 
[email protected]


Hi,

Suppose I want to do a similar thing AAA style. Namely, I have several
persons created by the CreatePersons method, and for each person, I
want to run the Setup method (with a Person argument) and several
tests. So, the questions are:
- Can we run a parametrized [Setup] the same way as [Test]?
- Can we have it class-wide, i.e., put [Factory("CreatePersons")] at
the class level?

Same question regarding the Row-style testing: can I apply the Row
attribute at the class level, and have all my Setup and Test methods
parametrized the same way, parameters taken from the class level
attribute?

Thanks

ulu

On Jan 21, 12:46 am, Jeff Brown <[email protected]> wrote:
> It looks like you're trying to produce a list of Person objects to pass to
> the tests.
> Try this:
>
> public class TestFixture
> {
>    public IEnumerable<Person> CreatePersons()
>    {
>        yield return new Person("Mike");
>        yield return new Person("Jim");
>    }
>
>    [Test]
>    [Factory("CreatePersons")]
>    public void Test1(Person p)
>    {
>         Assert.AreEqual("Max", p.Name);
>    }
>
>    [Test]
>    [Factory("CreatePersons")]
>    public void Test2(Person p)
>    {
>         Assert.AreEqual("Max", p.Name);
>    }
>
> }
>
> Here the output will look like:
>
> - Test1({Mike})
> - Test1({Jim})
> - Test2({Mike})
> - Test2({Jim})
>
> It should also be possible to combine data sources with suites like this.  I
> haven't tried it yet...
>
> [DynamicTestFactory]
> [Factory("CreatePersons")]
> public IEnumerable<Test> Suite(Person p)
> {
>     yield return new TestCase("Test1", () => {
>        // do something with p.
>     });
>
> }
>
> Jeff.
>
> On Tue, Jan 20, 2009 at 12:52 PM, max2256 <[email protected]> wrote:
>
> > Hi,
>
> > I'm new to MbUnit. I would like to know if there is a way of doing the
> > following with MbUnit V3 or any MbUnit version. (mixture of TestSuite
> > and DataDriven testing) :
>
> > [TestFixture]
> > public class TestFixture
> >  {
> >     [Row(typeof(Person), new Person("Max"))]
> >     [Row(typeof(Person), new Person("Mike"))]
> >     [Row(typeof(Person), new Person("Frank"))]
> >     [TestSuite]
> >     public TestSuite GetSuite(Person p)
> >     {
> >          // add tests to TestSuite
> >     }
>
> > 


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to