{"id":11,"date":"2008-07-27T13:28:57","date_gmt":"2008-07-27T11:28:57","guid":{"rendered":"http:\/\/floris.briolas.nl\/floris\/?p=11"},"modified":"2008-10-13T21:58:07","modified_gmt":"2008-10-13T19:58:07","slug":"datadriven-testing-with-excel","status":"publish","type":"post","link":"https:\/\/floris.briolas.nl\/floris\/2008\/07\/datadriven-testing-with-excel\/","title":{"rendered":"DataDriven Testing with Excel"},"content":{"rendered":"<p>Validating code with losts of scenario&#8217;s gets easier with validating the function with Excel. All you need is Excel.<\/p>\n<p>Start of by naming the variables in the first row, one variable per column. Add an extra column for the result value (or more if needed). Fill out the variables and results.<\/p>\n<pre name=\"code\" class=\"csharp\">\r\n\r\n[TestMethod]\r\n[DeploymentItem(\"bonusCalculation.xlsx\")]\r\n[DataSource(\"System.Data.OleDb\", \"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=bonusCalculation.xlsx;Extended Properties=Excel 12.0;Persist Security Info=False\", \"bonus$\", DataAccessMethod.Sequential)]\r\npublic void BonusCalcualtion()\r\n{\r\n    double result = Utils.GetSquareRoot(2);\r\n    double omzet = (double)TestContext.DataRow [\"Omzet\"];\r\n    double winst = (double)TestContext.DataRow[\"Winst\"];\r\n    double bonus = (double)TestContext.DataRow[\"Bonus\"];\r\n\r\n    Assert.AreEqual(bonus, Utils.BonusCalculation(omzet, winst));\r\n}\r\n\r\n<\/pre>\n<p>When you do not have Office 2007, but need to run the test with the .xlsx you might want to download the data driver : <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?displaylang=en&amp;FamilyID=7554f536-8c28-4598-9b72-ef94e038c891\"><br \/>\nat Microsoft<\/a><\/p>\n<p>If you prefer using an older fileformat of excel, compatible with MS Excel 2003 and 2000, use:<\/p>\n<pre name=\"code\" class=\"csharp\">\r\n[TestMethod]\r\n[DeploymentItem(\"bonusCalculation.xls\")]\r\n[DataSource(\"System.Data.OleDb\", \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='Calculator.xls';Persist Security Info=False;Extended Properties='Excel 8.0'\", \"bonus$\", DataAccessMethod.Sequential)]\r\n{\r\n    \/\/....\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Validating code with losts of scenario&#8217;s gets easier with validating the function with Excel. All you need is Excel. Start of by naming the variables in the first row, one variable per column. Add an extra column for the result value (or more if needed). Fill out the variables and results. [TestMethod] [DeploymentItem(&#8220;bonusCalculation.xlsx&#8221;)] [DataSource(&#8220;System.Data.OleDb&#8221;, &#8220;Provider=Microsoft.ACE.OLEDB.12.0;Data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[3],"tags":[5],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p61yPs-b","_links":{"self":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/11"}],"collection":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":8,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/11\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}