7

I am trying to execute the testcases programatically using the microsoft test manager using c#. For that I want to read the parameter values stored in Microsoft Test Manager. Please suggest me how to do that Eg:- Read the value of internal paramter "MY Value" I tried to enter the image but its not working ...

Regards Harsh

HarshJain
  • 327
  • 1
  • 4
  • 12

2 Answers2

8

I suppose you want to read the parameters from the datasource of the Test Case that your automated test implements.

You have to associate your test with the Test Case's Id on TFS.

Try the following code.

[TestClass]
public class TestClass
{
    public TestContext TestContext { get; set; }
    public DataRow DataRow { get; set; }

    [TestMethod]
    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", 
        "http://localhost:8080/tfs/[CollectionName];[ProjectName]", "[TestCaseId]", DataAccessMethod.Sequential)]
    public void TestMethod()
    {
        string column1 = TestContext.DataRow[0].ToString(); // read parameter by column index
        string column2 = TestContext.DataRow["Column2"].ToString(); //read parameter by column name
    }
}

Have in mind that your TestMethod will run one time for each row (iteration) of the Test Case's datasource.

chaliasos
  • 9,659
  • 7
  • 50
  • 87
  • Is the DataSource defined with the brackets around those Field names? Or are we meant to substitute with the values in the attribute? Thanks. – maxwellb May 31 '13 at 18:53
  • 2
    No, you don't need the brackets. Replace them with the actual values (e.g. "[TestCaseId]"--> "100"). – chaliasos Jun 01 '13 at 17:38
0

I think what you describe is Data-Driven Coded UI tests.

http://msdn.microsoft.com/en-us/library/ee624082.aspx

andreadi
  • 1,953
  • 1
  • 20
  • 35