Search code examples
c#unit-testingdatasourcemstestdata-driven-tests

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

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
}

Solution

  • It seems that the connection string was correct and visual studio had some dirt files. I end up Cleaning the solution and restarting Visual Studio and it worked