Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSTest.exe not copying all needed project DLLs?

I'm trying to get MSTest.exe to run, and it seems like testcontainer isn't being read properly; while my tests all run successfully in all config environments within Visual Studio.

the command I'm using is:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" /nologo /usestderr /testSettings:"C:\temp\MyProject\Sources\MyProject\Local.testsettings" /searchpathroot:"C:\temp\MyProject\Binaries" /resultsfileroot:"C:\temp\MyProject\TestResults" /testcontainer:"C:\temp\MyProject\Binaries\MyProject.Services.Server.UnitTests.dll" 

The project references within testcontainer project look like this:

<ItemGroup>
    <ProjectReference Include="..\..\Services\MyProject.Services.Server\MyProject.Services.Server.csproj">
        <Project>{92EC1999-CC0C-47DD-A4D6-17C3B1233C50}</Project>
        <Name>MyProject.Services.Server</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\SvcConfiguration\MyProject.ServiceConfiguration.Interfaces\MyProject.ServiceConfiguration.Interfaces.csproj">
        <Project>{8E2E7BA9-75DB-458E-A184-AC1030EAD581}</Project>
        <Name>MyProject.ServiceConfiguration.Interfaces</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\SvcConfiguration\MyProject.ServiceConfiguration.Services\MyProject.ServiceConfiguration.Services.csproj">
        <Project>{39514766-23A8-45DB-96EA-B6B4D9C8B086}</Project>
        <Name>MyProject.ServiceConfiguration.Services</Name>
    </ProjectReference>
</ItemGroup>

Neither the ServiceConfiguration.Interfaces nor the ServiceConfiguration.Services DLL is placed into the Out folder in TestResults.

The project GUIDs do match between the references and the referenced projects.

Is there something that I'm missing in the command line?

like image 816
Josh Russo Avatar asked Nov 10 '11 17:11

Josh Russo


3 Answers

mstest.exe will not coy all referenced dll's.

See a blog post on this at https://web.archive.org/web/20111221110459/http://www.dotnetthoughts.net/2011/11/22/mstest-exe-does-not-deploy-all-items/

like image 91
Anuraj Avatar answered Nov 04 '22 21:11

Anuraj


You can specify exactly what files are copied to the test directory using a test settings file. You can create multiple test settings files in Visual Studio, so you can have one for running from VS, another for running from MSTest, another for server CI builds, and so on. See here for more information: Create Test Settings to Run Automated Tests from Visual Studio

Use the /testsettings:<filename> option to specify it on the command line.

What seems to confuse people at first is that, by default, MSTest's "current directory" is not the MSTest launch directory, but the Out folder of the test results.

As mentioned previously, MSTest does not correctly infer all used assemblies, if you don't have a direct reference, it will not copy the assembly. That said, Visual Studio has similar behaviour in its build too, so a lot of people work around this by adding bogus code references - a terrible solution - I don't recommend it.

However, native DLLs are even more problematic, and I have found that explicitly copying them in the test configuration (test settings) works for them, just as for managed assemblies.

like image 26
user1164178 Avatar answered Nov 04 '22 22:11

user1164178


Whether it goes to Out or the build area depends on different factors, however, for the situations where it still doesn't work, you can use a DeploymentItem "hack", or, tweak your runsettings file.

Try looking at this answer: https://stackoverflow.com/a/33344573/2537017

like image 1
JamesDill Avatar answered Nov 04 '22 21:11

JamesDill