Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 991
elucid8 Avatar asked May 02 '13 20:05

elucid8


1 Answers

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.

like image 133
elucid8 Avatar answered Oct 11 '22 16:10

elucid8