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
You can use XML, Database, or CSV datasources MS Test. Create FooTestData.xml:
1
2
And set it as datasource for your test:
[TestMethod]
[DeploymentItem("ProjectName\\FooTestData.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
"|DataDirectory|\\FooTestData.xml", "Row",
DataAccessMethod.Sequential)]
public void FooTest()
{
int x = Int32.Parse((string)TestContext.DataRow["Data"]);
// some assert
}
BTW with NUnit framework it's match easier - you can use TestCase attribute to provide test data:
[TestCase(1)]
[TestCase(2)]
public void FooTest(int x)
{
// some assert
}