locked
XML data driven tests - using XPath in DataSource parameter tableName RRS feed

  • Question

  • Hello,

    I'm trying to filter out the tests that are executed based on some condition in my datasource file (which is XML). I'm trying to use a XPath expression in tableName parameter, but I have no luck:

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "Modules.xml", "/AllProductInfo/Modules/Module[Quality='Release']", DataAccessMethod.Sequential)]

    I receive error:

    Test Name: ReleaseProcesses_OpenAndValidate
    Test FullName: UITests.SharedTests.Sanity.Tests.ProcessesOpen.ReleaseProcesses_OpenAndValidate
    Test Source: D:\Work\2012.X\QA-Testing\UI Tests\CodedUI\Shared\Tests\Sanity\ProcessesOpen.cs : line 70
    Test Outcome: Failed
    Test Duration: 0:00:00

    Result Message: 
    The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" in the MSDN Library.
    Error details: Object reference not set to an instance of an object.

    When I use only Module as tableName parameter, the data is getted.

    I've tried to search the forums, but could not find similar example. Have you any experience with this? Can you accomplish this?

    Thanks,

    OlgA

    Tuesday, February 26, 2013 8:25 AM

Answers

All replies

  • Hi OlgA,

    Thank you for posting in the MSDN forum.

    Sorry for that I couldn’t repro this issue, if possible, you could share us a simple sample, so we could try to check it in my machine.

    But based on the error message, it means that it couldn’t connect to the data source. Maybe you could try to debug your unit test, and make sure that which line code generated this issue.

    As far as I know, if we want to use the data driven test with XML file, for example, in VS2010, it will generate the connect code automatically, for detailed information, see

    http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/059a98e6-2994-4da9-b03a-a8f0a8ef3448

    http://myramserialize.blogspot.com/2008/07/visual-studio-and-data-driven-unit.html

    If we use the VS2012, we have to add it manually, but it still has the default mode, so I doubt that it will not support it. Maybe you could share me a simple sample, I will try to check it.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 27, 2013 11:08 AM
  • Hello Jack,

    and thank you for the answer.

    I figured out that I cannot use XPath expressions in the DataSource definition... Fortunately I have found another solution.

    Cheers,

    ~Olga

    Wednesday, June 12, 2013 11:11 AM
  • I am facing the same problem when i use the xml data source file. I am using VS2012 update 4. 

    <?xml version="1.0" encoding="utf-8" ?>
    <DataRow>
      <Brugernavn>200 </Brugernavn>
      <Adgangskode>1234</Adgangskode>
    </DataRow>

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\data.xml", "Iterations", DataAccessMethod.Sequential), DeploymentItem("data.xml"), TestMethod]

    It works with CSV file but it shows this error when i use the xml. 

    The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.
    Error details: Object reference not set to an instance of an object. Please suggest any solution for this problem. I tested many solution but it does not work. 
    • Edited by riasatm Tuesday, December 9, 2014 4:13 PM
    Tuesday, December 9, 2014 4:13 PM
  • Hi riasatm,

    Since this case has been closed for a long time, to help you resolve this issue as soon as possible, would you mind posting a new case in our forum? Our team members would follow up your issue.

    Thank you for your support and co-operation.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 10, 2014 2:11 AM