Tuesday, 10 February 2015

How to use Coded UI test script to fetch data from MTM Test Cases

If we want to fetch the test data from MTM(Microsoft Test Manager) and use it inside our script we should follow the below steps:
  1. Open MTM
  2. Create a new Test case and insert the parameters
  3. Inside codedUITest file write the below code:
Following is the code to create a link between the test script and MTM Test Case

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.Test Case", "http://localhost:8080/tfs/[CollectionName];[Project Name]","TestCaseId", DataAccessMethod.Sequential),TestMethod]

Now if you want to access the parameters define inside the test case, Follow below code:

public void method_Name()
{
    string s1= TestContext.DataRow["param_Name"].ToString();

}

param_Name= is the name of parameter defined inside the MTM Test Case.