locked
How to create a data driven unit test RRS feed

  • Question

  • This is the error that I getting for this data driven unit test.  Can anyone help me with this question?

    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: Format of the initialization string does not conform to specification starting at index 33.

    <?

    xmlversion="1.0"encoding="utf-8"?>


    <

    configuration>


      <

    configSections>


        <

    sectionname="microsoft.visualstudio.testtools"type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>


        <!--

    <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />-->


      </

    configSections>


      <

    connectionStrings>


        <

    addname="MyJetConn"connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:MyTestProject\testdatasource.accdb; Persist Security Info=False;"providerName="System.Data.OleDb"/>


        <

    addname="MyExcelConn"connectionString="Dsn=Excel Files;dbq=C:\data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5"providerName="System.Data.Odbc"/>


      </

    connectionStrings>


      <

    microsoft.visualstudio.testtools>


        <

    dataSources>


          <

    addname="MyJetDataSource"connectionString="MyJetConn"dataTableName="MyDataTable"dataAccessMethod="Sequential"/>


          <

    addname="MyExcelDataSource"connectionString="MyExcelConn"dataTableName="Sheet1$"dataAccessMethod="Sequential"/>


        </

    dataSources>


      </

    microsoft.visualstudio.testtools>


    </

    configuration>


    using

    System;


    using

    Microsoft.VisualStudio.TestTools.UnitTesting;



    namespace

    TestProject1


    {


        [

    TestClass]


       

    publicclassUnitTest1


        {


           

    privateTestContextcontext;



           

    publicTestContextTestContext


            {


               

    get{ returncontext; }


               

    set{ context = value; }


            }



            [

    DeploymentItem("testdatasource.laccdb"), DeploymentItem("testdatasource.accdb"), TestMethod()]


            [

    DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"C:\\testdatasource.laccdb", "MyDataTable", DataAccessMethod.Sequential)]


           

    publicvoidMyTestMethod()


            {


               

    inta = Int32.Parse(TestContext.DataRow["Arg1"].ToString());


               

    intb = Int32.Parse(TestContext.DataRow["Arg2"].ToString());


               

    Assert.AreNotEqual(a, b, "A value was equal.");


            }



            [

    TestMethod()]


            [

    DeploymentItem("MyTestProject\\data.xlsx")]


            [

    DataSource("MyExcelDataSource")]


           

    publicvoidMyTestMethod2()


            {


               

    Assert.AreEqual(context.DataRow["Val1"], context.DataRow["Val2"]);


            }


        }


    }


    • Moved by Bob Shen Friday, March 23, 2012 9:19 AM (From:Visual C# General)
    Thursday, March 22, 2012 12:57 AM

Answers

All replies

  • Hi assaultkitty,

    Thank you for posting in the MSDN forum.

    Can you tell me which App you are testing, C# console app or others?

    Which line code generated this error? You could double click the result in the Test Result window, and we should make sure that whether it is related to your unit test methods or your class method which you want to create the unit test.

    How to: Create and Run a Unit Test

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

    How to: Create a Data-Driven Unit Test

    http://msdn.microsoft.com/en-us/library/ms182527(v=vs.100).aspx

    If no help, I hope you could share us the code about your class method, so we could try to repro this issue. Thanks for your understanding.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 23, 2012 9:38 AM
  • Hi assaultkitty,

    I am writing to check the status of the issue on your side. 

    What about this problem now?

    Would you mind letting us know the result of the suggestion?

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 26, 2012 3:01 AM