Data-Driven Unit Test with Excel 2007要点

app.config配置
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <configuration>
  3. <configSections>
  4. <sectionname="microsoft.visualstudio.testtools"type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection,Microsoft.VisualStudio.QualityTools.UnitTestFramework,Version=9.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/>
  5. </configSections>
  6. <!--addbelowline(s)fordatadriventest.-->
  7. <connectionStrings>
  8. <addname="MyExcelConn"connectionString="Dsn=ExcelFiles;dbq=UnitTestDataforFindOrders.xlsx;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5"providerName="System.Data.Odbc"/>
  9. </connectionStrings>
  10. <microsoft.visualstudio.testtools>
  11. <dataSources>
  12. <addname="MyExcelDataSource"connectionString="MyExcelConn"dataTableName="Sheet1$"dataAccessMethod="Sequential"/>
  13. </dataSources>
  14. </microsoft.visualstudio.testtools>
  15. </configuration>
测试方法
  1. [DeploymentItem("UnitTestDataforFindOrders.xlsx")]
  2. [DataSource("MyExcelDataSource"),TestMethod]
  3. publicvoidTestMethodUsingExcel()
  4. {
  5. stringxmlstring=TestContext.DataRow["OrderHistorySearchCriteria"].ToString();
  6. }

excel 文件中第一行为列名 OrderHistorySearchCriteria


你可能感兴趣的:(Excel,Microsoft)