elucid8
elucid8

Reputation: 1422

How to use multiple TestCaseSource attributes for an N-Unit Test

How do you use multiple TestCaseSource attributes to supply test data to a test in N-Unit 2.62?

I'm currently doing the following:

[Test, Combinatorial, TestCaseSource(typeof(FooFactory), "GetFoo"), TestCaseSource(typeof(BarFactory), "GetBar")]
FooBar(Foo x, Bar y)
{
 //Some test runs here.
}

And my test case data sources look like this:

internal sealed class FooFactory
{
    public IEnumerable<Foo> GetFoo()
    {
        //Gets some foos.
    }
}


    internal sealed class BarFactory
{
    public IEnumerable<Bar> GetBar()
    {
        //Gets some bars.
    }
}

Unfortunately, N-Unit won't even kick off the test since it says I'm supplying the wrong number of arguments. I know you can specify a TestCaseObject as the return type and pass in an object array, but I thought that this approach was possible.

Can you help me resolve this?

Upvotes: 17

Views: 8884

Answers (1)

elucid8
elucid8

Reputation: 1422

The appropriate attribute to use in this situation is ValueSource. Essentially, you are specifying a data-source for every argument, like so.

public void TestQuoteSubmission(
    [ValueSource(typeof(FooFactory), "GetFoo")] Foo x, 
    [ValueSource(typeof(BarFactory), "GetBar")] Bar y)
{
    // Your test here.
}

This will enable the type of functionality I was looking for using the TestCaseSource attribute.

Upvotes: 20

Related Questions