Running MsTest from the command line with a custom assembly base directory

前端 未结 2 981
面向向阳花
面向向阳花 2021-01-18 05:37

I did quite a lot of research on the web and tried a few settings, but I couldn\'t reproduce the behavior of running MsTest in Visual Studio 2012 on the command line.

<
相关标签:
2条回答
  • 2021-01-18 05:59

    This is due to an MSTest bug that sets the current directory to its own working directory, rather than the test project's bin (or deployment) folder. The workaround is to execute the following code in the constructor of your test class:

    Environment.CurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
    

    I got the idea from http://www.ademiller.com/blogs/tech/2008/01/gotchas-mstest-appdomain-changes-in-vs-2008/; however, note that, in my case at least, it required setting Environment.CurrentDirectory, rather than the reverse, as suggested in the article.

    0 讨论(0)
  • 2021-01-18 06:05

    After more searching we changed to use the test console runner that is included with VS2012:

    VSTest.Console.exe Tests\bin\Tests.dll /Framework:framework40 /Settings:LocalTestRun.testrunconfig

    This works with a relative path as applicationBaseDirectory.

    0 讨论(0)
提交回复
热议问题