I want to test the following method in C# for all code paths.
public int foo (int x)
{
if(x == 1)
return 1;
if(x==2)
return 2;
else
return 0;
}
I’ve seen this pex unit testing where multiple inputs are tested. How can I create a unit test that accepts multiple inputs?
[TestMethod()] //some setup here??
public void fooTest()
{
//some assert
}
I want to avoid creating a test method for each input. I am working with Visual Studio 2010/2012 and .Net 4.0
You can use XML, Database, or CSV datasources MS Test. Create FooTestData.xml:
And set it as datasource for your test:
BTW with NUnit framework it’s match easier – you can use TestCase attribute to provide test data: