Search code examples
c#unit-testingvisual-studio-2017outputdeploymentitem

DeploymentItem(Path, outputDirectory) not working in new Unit-Test project


i'm currently working on a task in a project. We have many Test-Projects in the solution reprository, which are using the DeploymentItem() attribute(all of the Tests are working).

My Problem:

I created a new Directory in the root of the reprository and in the Directory is a new Test-Project. The new tests are not deploying items or something else and using a wrong output path.(All tests not working because no items are deploying)

All old Test-Projects are using "TestResults" Directory. After every build/run of a test a new sub directory ist created named like "Deploy_xxx_Date". My Test-Project is using as output path the default directory bin/Debug. How can i change it that my Project is also using the default TestResults Directory automaticly? And which is the best way to Deploy items?

Hint:

output of old Tests: C:..\RootOfProject\SolutionDir\TestResults\generatedFolderWithDeploymentItems

output of my Tests: C:..\RootOfProject\Tests\ProjectDir\bin\Debug\NothingDeployed

my Project also should have this output Directory: C:..\RootOfProject\SolutionDir\TestResults\FolderWithDeploymentItems

Error after a test is running:

Test file 'C:Tests\TESTPROJECT\bin\Debug\ItemWhichShouldBeDeployed' does not exist.


Solution

  • You should change the properties of the item in the Test project that need be copied as Deployment Item. Right click on the item and set following options Build Action : None and Copy to output Directory : Copy always or Copy if newer (see below), save the project and try again.

    enter image description here