Data driven tests with mstest framework

  • 1 Replies
  • 1212 Views
Data driven tests with mstest framework
« on: April 27, 2016, 16:19:27 pm »
I wrote a test method that receives 2 files and compares them.

Code
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) ?

*

Ruhit

  • *
  • 22
Re: Data driven tests with mstest framework
« Reply #1 on: April 27, 2016, 17:34:57 pm »
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:

Code
[TestClass]
public class MyTests
{
    [TestMethod]
    [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; }
}


 

Sitemap 1 2 3 4 5 6 7 8