Note that there are some explanatory texts on larger screens.

plurals
  1. POPros and cons of Data Driven Unit Testing (Excel data source)
    text
    copied!<p>Since last few days I was working on Data driven unit testing. I used Excel spreadsheet as data source. Although it decreases the redundant code in my test method (instead of writing all test data in test method and calling same function everytime) but on the other hand I think it is making my Unit test complicated(with configuration Settings, parsing data from Excel, unexpected exceptions..etc). Can anyone please shed some light on the pros and cons of each approach. For better understanding I am writting below a sample test method with and without data source:</p> <p><strong>With Data Source</strong></p> <pre><code>[TestMethod] [DataSource("CompanyAddressInfo_DataSource")] [DeploymentItem("CoreUnitTests\\CompanyUnitTests\\CompanyTestData.xlsx")] public void CompanyAddressInfo_GetItem_Test() { if (TestContext.DataRow["Company_No"] != DBNull.Value) { bool expected = false; bool actual=false; if (TestContext.DataRow["Expected"].ToString() == "Y") expected = true; long Company_No = Convert.ToInt64(TestContext.DataRow["Company_No"]); CompanyAddressInfo obj = CompanyAddressInfo.GetItem(Company_No); if (obj != null) {actual = (obj.Company_No == Company_No);} Assert.AreEqual(expected,actual); } } </code></pre> <p><strong>Without Data Source</strong></p> <pre><code>[TestMethod] public void CompanyAddressInfo_GetItem_Test() { bool actual=false; long Company_No; Company_No = 20; CompanyAddressInfo obj = CompanyAddressInfo.GetItem(Company_No); actual = (obj.Company_No == Company_No); Assert.AreEqual(true,actual); Company_No = 23; CompanyAddressInfo obj = CompanyAddressInfo.GetItem(Company_No); actual = (obj.Company_No == Company_No); Assert.AreEqual(false,actual); ..............so on } </code></pre> <p>Please note that above mentioned code is just an example. Also, another alternative to data driven unit testing I thought could be to make a generic function for calling dll and pass test data to this function (Hence reducing the redundancy). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload