I have a unit-test that tests a variety of cases, like this:
public void Test1(Int32 a, Int32 b, Int32 c)
Let's say I want to create test-code without a loop, so I want to use TestCase to specify parameters like this:
[TestCase(1, 1, 1)]
public void Test1(Int32 a, Int32 b, Int32 c)
Is it possible for me with this attribute to say this:
Ie. something like this:
[TestCase(new[] { 1, 2, 3, 4 }, new[] { 1, 2, 3, 4 }, new[] { 1, 2, 3, 4 })]
public void Test1(Int32 a, Int32 b, Int32 c)
Doesn't seem like it, but perhaps I'm overlooking something?
This attribute that helps in coming up with an NUnit parameterized test also supports several additional named parameters like Author, Category, Description, ExpectedResult, TestName, etc. The execution order of the TestCase attribute can vary when used in combination with other data-providing attributes.
There are other NUnit attributes that enable you to write a suite of similar tests. A [TestCase] attribute is used to create a suite of tests that execute the same code but have different input arguments. You can use the [TestCase] attribute to specify values for those inputs.
The first way to create data driven tests is by using the [TestCase] attribute that NUnit provides. You can add multiple [TestCase] attributes for a single test method, and specify the combinations of input and expected output parameters that the test method should take.
NUnit provides the Values attribute which can be used together with Combinatorial attribute to achieve this:
[Test, Combinatorial]
public void Test1(
[Values(1,2,3,4)] Int32 a,
[Values(1,2,3,4)] Int32 b,
[Values(1,2,3,4)] Int32 c
)
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With