简体   繁体   中英

MSTest Unit Test Adapter Failing to Connect to Data Source When Tests From New Test Project Are Introduced to Solution

I have a test solution set up with two unit test projects in it. Both project directories are set up the same way to run data driven tests:

Project1 -> TestData -> Project1TestData -> MyTestData.xml

and each each Method has:

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
    @"|DataDirectory|\TestData\Project1TestData\MyTestData.xml",
    "test",
    DataAccessMethod.Sequential)
]

Each project also has an app.config file that is used for setup during TestInitialize methods. After introducing the second test project, and trying to run a test method created in that project, I keep getting a message:

Result Message:

The unit test adapter failed to connect to the data source or to read the data. Error details: Object reference not set to an instance of an object.

However, my tests from TestProject1 work just fine. I have set the CopyToOutputDirectory to CopyAlways on all of the files needed to run the test in TestProject2 and it still fails.

I'm wondering whether there is any way to fix this or if I need to create a separate solution for my second test project, in order to get the tests to run properly?

After trying to find a fix for several days I stumbled upon something that seems to have solved this issue:

Go to Test -> Test Settings -> Default Processor Architecture -> Change x86 to x64

I don't really know all that much about MSTest's test adapter, processor architecture compatibility or, specifically, what is causing this issue, so someone who knows more about this can chime in as to whether this is a legitimate solution.

For me, the issue was that for whatever reason, I did not have a test settings file selected. Test > Test Settings > Select Test Settings File did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM