locked
Help on data driven testing RRS feed

  • Question

  • I’m implementing a data driven test using VS 2010. I’m using XML as data source. Below is the XML im using for data source.  The test method will run for each “Row” in the XML.

    1>     Currently, for the same inputID, the Process method hits the database for each Row. I would like to get vehicle only once for all the rows. How do I do that?

    2>     Is there any way I can define inputID in the XML itself, instead of hardcoding in test method. Is this case how the XML will look and how do I retrieve the InputID from XML?

     

    <?xml version="1.0" encoding="utf-8" ?>
    <VehicleListingTestData>
      <Row>
        <ColumnName>A</ColumnName>
        <RowNumber>10</RowNumber>
        <Result>200</Result>
      </Row>
      <Row>
        <ColumnName>A</ColumnName>
        <RowNumber>10</RowNumber>
        <Result>200</Result>
      </Row>
      <Row>
        <ColumnName>A</ColumnName>
        <RowNumber>10</RowNumber>
        <Result>200</Result>
      </Row>
    </VehicleListingTestData>

      

     [DeploymentItem("\\TestData\\VehicleListingTestData.xml"), TestMethod]

            [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML""|DataDirectory|\\VehicleListingTestData.xml""Row"DataAccessMethod.Sequential)]

            public void MyTestMethod()

            {

                string column = (string)TestContext.DataRow["ColumnName"];

                string rowName = (string)TestContext.DataRow["RowNumber"];

                string result = (string)TestContext.DataRow["Result"];

                Process(10, column, rowName, result);

            }

     

            private static void Process(string inputID, string Column, string RowName, string Result)

            {

                VehicleMapper _vehicleMapper = new VehicleMapper();

                Vehicle veh = _vehicleMapper.GetVehicleFromTheDatabase(inputID);

                string actualValue = veh.GetValue(Column, RowName);

                Assert.AreEqual(Result, actualValue);

            }

     

    Monday, November 28, 2011 7:50 PM

All replies