数据驱动unit testing问题

我有一些麻烦让我的unit testing设置为使用Excel .xlsx数据源。

我的App.config文件:

   

我已经validation它正在找到TestData.xlsx ,并且有一个名为GetAllCellNamesTest的工作表。

在我的unit testing类中,我有以下设置:

  [TestMethod()] [DeploymentItem("TestProject\\TestData.xlsx")] [DataSource("GetAllCellNamesTest")] public void GetAllCellNamesTest() { // ... test code 

TestData.xlsx正被复制到测试结果目录中,并且所有不尝试引用数据源的unit testing都将被传递。

但是,这一个测试失败并显示以下消息:

 The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: ERROR [42S02] [Microsoft][ODBC Excel Driver] The Microsoft Access database engine could not find the object 'GetAllCellNamesTest$'. Make sure the object exists and that you spell its name and the path name correctly. If 'GetAllCellNamesTest$' is not a local object, check your network connection or contact the server administrator. 

我真的不确定我的设置在哪里出错了,我在MSDN上按照这个演练来进行设置: 演练:使用配置文件来定义数据源 。 请注意,我确实将section版本更改为10.0.0.0因为我使用的是.net 4.0(根据页面底部的注释)。

编辑:哦,所有文件都位于我的计算机本地。

您是否尝试过使用完整的文件路径?

文件是只读的吗?

您还可以指定要作为TestSettings的一部分部署的文件/目录。 这将节省您必须为每个测试方法放置DeploymentItem属性的工作量。

你之后使用配置;