TestProject Forum
Powered by leading experts in the test automation community

Data driven tests with mstest framework

I wrote a test method that receives 2 files and compares them.

Assert.IsTrue(MyFileUtils.FilesContentEqual(File1, File2));

I have a 2 arrays of files which I want to run in a loop, to compare each file to the corresponding file in the 2nd array.

I found out that I can use the DataSource attribute. But how would I pass 2 arrays (or a Dictionary) ?

You could use a CSV file as a DataSource that will have 2 columns (one for each array). Use it in your test method like so:

public class MyTests
    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "files.csv", "files#csv", DataAccessMethod.Sequential)]
    public void TestCase()
        TestLogic testObj = new TestLogic();

        string file1 = (string) TestContext.DataRow["firstArray"];     
        string file2 = (string) TestContext.DataRow["secondArray"]; 

        File1 = .... get file from file1 string
        File2 = .... get file from file2 string

        Assert.IsTrue(MyFileUtils.FilesContentEqual(File1, File2));

   public TestContext TestContext{ get; set; }