数据驱动单元测试问题 [英] Data driven unit tests problem
问题描述
我在设置单元测试以使用Excel .xlsx数据源时遇到了一些麻烦。
I'm having some troubles getting my unit tests to be setup to use an Excel .xlsx data source.
我的App.config文件:
My App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
<connectionStrings>
<add name="TestData" connectionString="Dsn=Excel Files;dbq=TestData.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
</connectionStrings>
<microsoft.visualstudio.testtools>
<dataSources>
<add name="GetAllCellNamesTest" connectionString="TestData" dataTableName="GetAllCellNamesTest$" dataAccessMethod="Sequential"/>
</dataSources>
我有验证是否找到了 TestData.xlsx
,并且有一个名为 GetAllCellNamesTest
的工作表。
I have verified that it is finding TestData.xlsx
, and there is a sheet named GetAllCellNamesTest
.
在我的单元测试课中,我进行了以下设置:
In my unit test class, I have the following setup:
[TestMethod()]
[DeploymentItem("TestProject\\TestData.xlsx")]
[DataSource("GetAllCellNamesTest")]
public void GetAllCellNamesTest()
{
// ... test code
TestData.xlsx
正在被复制到测试结果目录,并且所有不尝试引用数据源的单元测试都通过了。
TestData.xlsx
is being copied to the test results directory and all the unit tests which don't try to reference the data source are passing.
但是,此测试失败了,以下消息:
However, this one test is failing with the following message:
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上按照此演练进行了了解设置:演练:使用配置文件定义数据源。请注意,我确实将部分
的版本更改为 10.0.0.0
,因为我使用的是.net 4.0(请注意页面底部)。
I'm really not sure where in my setup is wrong, I followed this walkthrough on MSDN to get setup: Walkthrough: Using a Configuration File to Define a Data Source. Note that I did change the section
version to 10.0.0.0
because I am using .net 4.0 (per the note at the bottom of the page).
编辑:哦,所有文件都位于我的计算机上。
edit: oh, and all files are located locally on my computer.
推荐答案
您是否尝试过使用完整文件路径?
Have you tried using a full file path?
文件是只读的吗?
这篇关于数据驱动单元测试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!