Is it allowed to combine attributes "Combinatorial" and "TestCaseSource" ?

1,043 views
Skip to first unread message

Milan_Milan

unread,
Jul 7, 2010, 1:19:44 PM7/7/10
to NUnit-Discuss

Hi all,

I have two sets/arrays of the data:
1. FilterCombinationTestObject
2. FilterEntitiesTestObject

and I would like to make a test which will run with all combinations
of objects from this two arrays:
(apples) , ("ssdd", "ssDd")
(apples) , ("sdf", "sdf")
(apples), ("sdf", "sdfsdf")

(pear ), ("ssdd", "ssDd")
(pear) , ("sdf", "sdf")
(pear ), ("sdf", "sdfsdf")
...

so I declared test function with the following attributes:

[Test, Combinatorial, TestCaseSource("FilterCombinationTestObject"),
TestCaseSource("FilterEntitiesTestObject")]
public void SimpleTextFilterTest(TestPaarString sBaseString, string
sFilterEntity)


but I failed to get wanted list of test cases in NUnit GUI. Is it
possible to use Combinatorial attribute in combination with two
TestCaseSource array objects ?

Br,
Milan.


/* filter test data */
static object[] FilterCombinationTestObject =
{
new TestPaarString ("ssdd", "ssDd" ),
new TestPaarString ( "sdf", "sdf" ),
new TestPaarString ( "sdf", "sdfsdf" ),
};

/* filter test data */
static object[] FilterEntitiesTestObject =
{
new string[] { "apples"},
new string[] { "pear" },
new string[] { "mellons" },
};

public class TestPaarString
{
public TestPaarString(string sBase, string sSearched )
{
sBaseString = sBase;
sSearchedValue = sSearched;
}
string sBaseString;
string sSearchedValue;
};

Charlie Poole

unread,
Jul 7, 2010, 2:06:44 PM7/7/10
to nunit-discuss
Hi Milan,

Yes, it's possible to combine multiple sources off data but in your case there
is no data for 'Combinatorial' to operate on.

CombinatorialAttribute is one of several attributes that tell NUnit
how to combine
individual arguments specified as an attribute on one of the method parameters.
In fact it's the default, so is not actually needed except or documentary
purposes.

TestCaseSource attribute applies to the test method and gives a complete
test case with all needed arguments. It has no interaction with Combinatorial.

If you want all combinations of several possible arguments, then you need
to specify the values on each method parameter, for example, like this...

[Test]
public void SimpleTextFilterTest(
[ValueSource("xxxx")] TestPaarString sBaseString,
[ValueSource("yyyy")] string sFilterEntity)
{ ...

Charlie

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>

Milan_Milan

unread,
Jul 7, 2010, 2:37:46 PM7/7/10
to NUnit-Discuss
Hi Charlie,

I got it, thanks!
but in NUnit GUI I have no values written but in this case just tests
with allways the same name:
SimpleTextFilterTest(namespace.testClassName+TestPaarString,
System.String[])
repeated combinatorical number of times.

Why parameter values are not displayed ?

BR,
Milan.
> > For more options, visit this group athttp://groups.google.com/group/nunit-discuss?hl=en.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

cliff

unread,
Jul 7, 2010, 2:48:37 PM7/7/10
to nunit-discuss
On Wed, Jul 7, 2010 at 2:37 PM, Milan_Milan <milan.vuk...@googlemail.com> wrote:
Hi Charlie,

I got it, thanks!
but in NUnit GUI I have no values written but in this case just tests
with allways the same name:
SimpleTextFilterTest(namespace.testClassName+TestPaarString,
System.String[])
repeated combinatorical number of times.

Why parameter values are not displayed ?

you need to provide an override of the ToString() method of your TestPaarString class.  As for the array of strings, you might have to put a feature request to have NUnit loop through the array and print the values, or create another custom class to help facilitate this or restructure your test method and remove the array requirement.

--
thanks

cliff

Charlie Poole

unread,
Jul 7, 2010, 3:20:15 PM7/7/10
to nunit-discuss
I believe there is such a request (to display array content in name)
but it might be good to locate and comment it with this example.

Charlie

Milan_Milan

unread,
Jul 8, 2010, 5:45:01 AM7/8/10
to NUnit-Discuss
Hi Cliff and Charlie,

I overwrote class's ToString method and it works.

@Charlie
do you need me to check for such feature request because just with
overwriting class method it works. So for me this problem is resolved.

br,
Milan.


On 7 Jul., 20:48, cliff <powerd...@aol.com> wrote:
> On Wed, Jul 7, 2010 at 2:37 PM, Milan_Milan <
>

Charlie Poole

unread,
Jul 8, 2010, 9:48:55 AM7/8/10
to nunit-...@googlegroups.com
Cliff's suggestion was about the array parameter, which is probably shown as
only <String[]> - no need to check though - the request is already there.

Charlie

Reply all
Reply to author
Forward
0 new messages