How to set the working directory for MS Test projects

前端 未结 3 1745
隐瞒了意图╮
隐瞒了意图╮ 2021-02-07 11:32

how can I set the working directory for MS Tests projects, like I can do it for normal application projects? My Component that is tested need to access some config files that ar

3条回答
  •  野的像风
    2021-02-07 11:59

    For those who use Visual Studio 2012, if you set the output directory of the test project under Properties|Build|OutputPath then that will become the working directory when you run the tests from Visual Studio (since it is using Vstest.console.exe). If you don't want to have your test dlls, etc output to the same directory as your other files and you don't want to have the other files as content in your test project (as suggested by Schaliasos) then you can set the path on startup in a method that has the [AssemblyInitialize] attribute. You do this by assigning System.Environment.CurrentDirectory as usual. You will probably want to have the working directory as a setting or read from a configuration file.

    Edit

    As pointed out by Rohit.Net, when you choose Run All Tests the default path would be under TestResults. The same applies when using a runsettings file. The output folder will be the default working directory when you are not using DeploymentItems and: -

    • You right click the test(s) in Visual Studio and choose to run / debug, or
    • You run from the command line using vstest.console.exe.

提交回复
热议问题