单元测试错误 - 单元测试适配器未能连接到数据源或读取数据 [英] Unit Testing Error - The unit test adapter failed to connect to the data source or to read the data

查看:860
本文介绍了单元测试错误 - 单元测试适配器未能连接到数据源或读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VSTS 2K8,我已经建立了一个单元测试项目。在这里面,我有,做一个简单的断言方法的测试类。我使用的Excel 2007电子作为我的数据源

I'm using VSTS 2K8 and I've set up a Unit Test Project. In it, I have a test class with a method that does a simple assertion. I'm using an Excel 2007 spreadsheet as my data source.

我的测试方法是这样的:

My test method looks like this:

        [DataSource("System.Data.Odbc", 
        "Dsn=Excel Files;dbq=|DataDirectory|\\MyTestData.xlsx;defaultdir=C:\\TestData;driverid=1046;maxbuffersize=2048;pagetimeout=5", 
        "Sheet1", 
        DataAccessMethod.Sequential)]
    [DeploymentItem("MyTestData.xlsx")]
    [TestMethod()]
    public void State_Value_Is_Set()
    {
        string expected = "MD";
        string actual = TestContext.DataRow["State"] as string;
        Assert.AreEqual(expected, actual);
    }



作为方法的装饰属性说明的,我的Excel电子表格是我的本地C :/ 驾驶。在这里面,在我所有的数据所在的表名为Sheet1中。

As indicated in the method decoration attributes, my Excel spreadsheet is on my local C:/ Drive. In it, the sheet where all of my data is located is named "Sheet1".

我复制Excel电子表格导入我的项目,我设置的构建行动=内容和是否有更新的复制我已经设置其复制到输出目录=。

I've copied the Excel spreadsheet into my project and I've set its Build Action = "Content" and I've set its Copy to Output Directory = "Copy if Newer".

当试图运行这个简单的单元测试,我收到以下错误:

When trying to run this simple unit test, I receive the following error:

单元测试适配器未能连接到数据源或读取数据。有关解决此错误的详细信息,请参见MSDN Library中的疑难解答数据驱动的单元测试(http://go.microsoft.com/fwlink/?LinkId=62412)。
错误信息:错误[42S02] [微软] [ODBC Excel驱动程序]的Microsoft Office Access数据库引擎找不到对象'工作表Sheet1。请确保该对象存在并且,您拼写其名称和正确的路径名。

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 Office Access database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.

我已经验证了表名称拼写正确(即Sheet1中),我已经验证了我的数据源是否设置正确。

I've verified that the sheet name is spelled correctly (i.e. Sheet1) and I've verified that my data sources are set correctly.

网络搜索没有打开了太大的所有。而且我完全难住了。

Web searches haven't turned up much at all. And I'm totally stumped.

所有帮助或输入的是赞赏!!!!

All help or input is appreciated!!!!

推荐答案

Excel的格式(.xlsx)中的生成操作属性更改为内容和复制到输出目录,如果新的复制。

Change the "Build Action" property of Excel(.xlsx) to Content and "Copy to Output Directory" to Copy if newer.

这工作对我来说,当我得到了同样的错误URS ...

This worked for me when I got the same error as urs...

++也不要忘记浏览和TestRun.config文件,是在服务器soution的部署选项卡中添加的Excel文件.. :)

++ also dont forget to browse and add the excel file in Deployment tab of TestRun.config file that is in the server soution..:)

这篇关于单元测试错误 - 单元测试适配器未能连接到数据源或读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆