如何configurationapp.config使用Nunit从Excel文件中获取testing数据?

我正在尝试使用selenium,C#和Nunit来创build一个数据驱动的testing。 我正在使用app.config来查找我的Excel表,以便它可以运行testing

<appSettings> <add key="mydatafile" value="DataSource=C:\Users\christophermclellan\theExample.xlsx"/> </appSettings> 

我已经按照如下方式设置了我的configuration

 setting = ConfigurationManager.AppSettings["mydatafile"]; 

并阅读我的价值如下

 xlWorkBook = xlApp.Workbooks.Open(setting, 0, true, 5, "", "", true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); 

当我运行这个我得到以下错误

DataDrivenTestFramework.Driver.GoogleSearch:System.Runtime.InteropServices.COMException:对不起,我们找不到Data Source = C:\ Users \ christophermclellan \ theExample.xlsx。 它可能被移动,重命名或删除?

如果有人能指出我从哪里去的正确方向,那么你是伟大的

谢谢

克里斯

你不需要string的DataSource部分,只需要文件的path。 你也需要逃避你的道路,例如:

 <add key="mydatafile" value="C:\\Users\\christophermclellan\\theExample.xlsx"/>