Unit test cases on excel sheet RRS feed

  • Question

  • Hi 

    Can you please answer the following questions?

    How to read excel sheet data in to unit test class?

    How to send excel sheet data to data table?

    How to write unit test cases on this data table  in visual studio 2013 using c#?

    Thanks & Regards


    Friday, May 16, 2014 6:19 AM


  • You can use Excel as input for unit tests to run same test with multiple set of inputs. This is called as Data driven test.

    Articles for the same: How To: Create a Data-Driven Unit Test

    You will have to use below datasource for Excel:

    DataSource("System.Data.Odbc", "Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};dbq=|DataDirectory|\\Data.xls;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5;readonly=true", "Sheet1$", DataAccessMethod.Sequential), TestMethod]

    Data.xls is name of the Excel file. Sheet1 is the worksheet from which data will be read.


    Friday, May 16, 2014 6:34 AM