Excel에서 .xlsx 데이터 소스를 사용하도록 설정 테스트를하는 데 문제가 있습니다.데이터 구동 유닛 테스트 문제
내 app.config 파일은 :
<?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
라는 이름의 시트가있다.
[TestMethod()]
[DeploymentItem("TestProject\\TestData.xlsx")]
[DataSource("GetAllCellNamesTest")]
public void GetAllCellNamesTest()
{
// ... test code
TestData.xlsx
이 테스트 결과 디렉토리 및 전달하는 데이터 소스를 참조하려고하지 않는 모든 단위 테스트에 복사되는 : 내 단위 테스트 클래스에서
, 나는 다음과 같은 설정이있다.
그러나,이 테스트는 다음 메시지와 함께 실패 : Walkthrough: Using a Configuration File to Define a Data Source :
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 (페이지 하단의 참고 사항)을 사용하고 있기 때문입니다.
편집 : 오, 모든 파일이 내 컴퓨터에 로컬로 있습니다.
이것은 내가 MSTest보다 NUnit 및 xUnit를 선호하는 이유 중 하나입니다. [TestCase] 또는 [Theory]를 사용하여 코드로 모두 작업하는 것이 더 편리합니다. – Mathias