locked
Data-Driven Testing with Excel Files - Using One worksheet for one test method. RRS feed

  • Question

  • I am trying to use Excel files for Data-Driven Unit testing.  I have created my dataSources inside the configuration file as mentioned in this walkthrough:

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

    What i want to do is have one work sheet for every test method that I have.  I can do this by creating multiple datasources in the app.config file.  But I tried using the datasource without the dataTable like this :

    <add name="TestDataSourceExcel" connectionString="TestDataExcelConn" dataAccessMethod="Sequential"/>		

    and I declared my testmethod like this:

            [TestMethod]
            [DataSource("TestDataSourceExcel""Sheet1$")]
            public void MyTestMethod()

    I'm getting the error "The unit test adapter failed to connect to the data source or to read the data" if I do it like this.  Is there a better way to do this?  I do not want to create a datasource for every test method that I have.  I'm testing different models in each TestMethod and hence cannot use the same Sheet.  

    Can someone explain me how to do this without using multiple datasources?

    Thanks in advance.

     

     

    Friday, October 29, 2010 11:25 PM

Answers

  • Ravi,

    In addtion to my previous reply, if you have a look at Mark's solution, you'll find that he decorates his methods with the connection string. Now this is not terribly elegant, but there is a better solution. You can create a base class for your tests in which you set the TestContext.DataConnection yourself. This can then come from app.config, hard coded etc.

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, November 3, 2010 10:50 AM

All replies

  • Hi Ravi,

    I have not done this before, but you can have a look here. Mark Nichols has a very thorough blog post explaining how to set it up.

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, November 3, 2010 10:39 AM
  • Ravi,

    In addtion to my previous reply, if you have a look at Mark's solution, you'll find that he decorates his methods with the connection string. Now this is not terribly elegant, but there is a better solution. You can create a base class for your tests in which you set the TestContext.DataConnection yourself. This can then come from app.config, hard coded etc.

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, November 3, 2010 10:50 AM