locked
The unit test adapter failed to connect to the data source or to read the data RRS feed

  • Question

  • I trying to implement data driven test using Visual Studio. I'm using XML file as my data source. The xml is in the root of the test project. But when i run the project i get error "The unit test adapter failed to connect to the data source or to read the data". Below is my testMethod, I have tried different path(s) for DeployementItem thinkign may be the path is wrong but no luck yet.

     

     [TestMethod]
            [DeploymentItem(@".\VehicleListingTestData.xml")]
            [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
                       "|DataDirectory|\\VehicleListingTestData.xml",
                       "TestData",
                        DataAccessMethod.Sequential)]
            public void GenerateVehicleListingReport_WhenConfiguredInXml()
            {
                string column = (string)TestContext.DataRow["ColumnName"];
                string rowName = (string)TestContext.DataRow["RowName"];
                string result = (string)TestContext.DataRow["Result"];
    
                TestData(column, rowName, result);
            }
    

    I also have one more question. if i want to setup datasource Using a Configuration File what would be the connection string for XML file. I read the MSDn article here http://msdn.microsoft.com/en-us/library/ms243192.aspx but it only shows excel and access, NO XML.

    Monday, November 28, 2011 3:46 PM

All replies

  • i found the issue, my path was invalid. One more question though. is this a valid XML structure to use as datasource

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

     

    Monday, November 28, 2011 5:05 PM
  • I think xml has some limitation and it doesnt support multiple level nodes. For an example, seehttp://blogs.msdn.com/b/andyphilpotts/archive/2007/06/20/easily-bind-to-csv-or-xml-data-sources.aspx

    Thanks,

    Anuj


    http://www.anujchaudhary.com
    Tuesday, November 29, 2011 5:16 AM
  • sorry but that didnt solve my issue. The example provided in the link has the following XML file

    <SampleData>
      <Users>
        <UserName>Tony</UserName>
        <Role>Guest</Role>
      </Users>
      <Users>
        <UserName>Andy</UserName>
        <Role>Admin</Role>
      </Users>  
      <Products>
        <ProductName>SuperMixer 3000</ProductName>
        <Quantity>16</Quantity>
      </Products>
      <Products>
        <ProductName>Bath Magic</ProductName>
        <Quantity>5</Quantity>
      </Products>  
    </SampleData>

     

    but it does not show how to select two tables using DataSourceAttribute. How do i select "Users" & "Products" below?

    [DeploymentItem("TestData.xml"), TestMethod]
            [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML""|DataDirectory|\\TestData.xml""Users"DataAccessMethod.Sequential)]
            public void MyTestMethod()
            {
                
                
            }
    Tuesday, November 29, 2011 3:27 PM