How to make unit test run in bin folder

前端 未结 6 1509
遇见更好的自我
遇见更好的自我 2020-12-18 20:31

I\'m trying to access a file in my solution structure during the unit test. My unit test project has the bin\\Debug\\ as the output directory. So I have written

6条回答
  •  一生所求
    2020-12-18 20:54

    You can do this by using a .runsettings file, and setting false. See the "Remarks" section here. However, you can't do this if you are using a .testsettings file, and if you want to be able to inspect any files that your tests read or write after a failed run, you might not be able to, because they could be tainted by further tests etc.

    Another option is to use deployment items, which can be done through the DeploymentItemAttribute or through your .testsettings file. The attribute mechanism is preferred, and basically, on test methods that you need to deploy files for you do the following:

    [DeploymentItem(@"source", @"target")]
    public void Test1() {}
    

    Where source is either a path relative to the build output folder, or an absolute path, and target is either a path relative to where the tests run from, or an absolute path. You can leave the target parameter out, in this case it will assume a target of ".", ie the folder where the tests are running from. The docs for this are here

提交回复
热议问题