How to use multiple TestCaseSource attributes for N-Unit Test

How do you use several TestCaseSource attributes to submit test data for a test in N-Unit 2.62?

I am 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, the N-Unit will not even begin testing, as it says that I am supplying the wrong number of arguments. I know that you can specify TestCaseObject as the return type and pass an array of objects, but I thought this approach is possible.

Can you help me solve this problem?

+7
source share
1 answer

The appropriate attribute to use in this situation is ValueSource . Essentially, you specify a data source for individual parameters, for example.

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

This will allow you to use the type of function I was looking for using the TestCaseSource attribute.

+10
source

All Articles