简体   繁体   English

如何在单元测试项目中从不同文件夹访问数据源?

[英]How can I access data source from different folders in my unit test project?

I am using MSTest and trying to use my Data sources in different folder but I get 我正在使用MSTest并尝试在其他文件夹中使用我的数据源,但是我得到了

test adapter failed to connect 测试适配器连接失败

My project looks like this 我的项目看起来像这样

Project
|__Tests
   |___TestSuite1
   |   |___UnitTest1.cs
   |   |___Data1.csv
   |
   |___TestSuite2
       |_UnitTest2.cs
       |_Data2.csv
       |_Data2OtherScenario.csv

Do you know what might be wrong with my connection string? 您知道我的连接字符串可能出什么问题吗?

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Tests\\TestSuite2\\Data2.csv", "Data2.csv", DataAccessMethod.Sequential), DeploymentItem("Data2.csv")]
[TestMethod]
public void Test1(){
   //Test
}

It seems that the connection string was correct and visual studio had some dirt files. 似乎连接字符串正确,Visual Studio中有一些污垢文件。 I end up Cleaning the solution and restarting Visual Studio and it worked 我最终清洗了解决方案并重新启动Visual Studio,它正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Unit测试方法访问数据文件? - How can I access a data file from a Unit test method? 如何从基于硒的单元测试项目访问Web项目? - How to access web project from selenium based unit test project? 当新测试项目的测试被引入解决方案时,MSTest单元测试适配器无法连接到数据源 - MSTest Unit Test Adapter Failing to Connect to Data Source When Tests From New Test Project Are Introduced to Solution 如何在我的Visual Studio 2012项目中引用XML文件作为项目代码中的数据源? - How can I reference an XML file in my Visual Studio 2012 project as a data source in my project code? 如何将单元测试项目添加到现有MVC3应用程序(从空模板) - How Can I Add a Unit Test Project to an Existing MVC3 Application (from empty template) 如何为我的项目文件夹拒绝目录列表? - how can i do Directory Listing Denied for my project folders? 如何检测我的游戏文件夹中是否有不同的文件夹? - how can i detect if there are different folders in the my game folder? 如何对WCF客户端类进行单元测试? - How can I unit test my WCF client class? 我怎么知道我的程序在单元测试环境下 - How can I tell that my program is under unit test environment 如何对自定义验证属性进行单元测试 - How can I unit test my custom validation attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM