1

nice day!

I have following project structure:

Solution
-My.Project
-My.Project.Test
--Resources
---mytest.file

In my test file following method:

[TestMethod]

[DeploymentItem("My.Project.Test\\Resources\\mytest.file", @"Resources")]

TestMethod()

{

....

string path = "Resources\\mytest.file"; ....

}

In according to http://msdn.microsoft.com/en-us/library/ms182475%28v=vs.100%29.aspx I want use only DeployItemAttribute without "Deployment Items property".

But when I debugged it method, I catch "File not found exception".

What can I do?

PS: also posted this question in http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/474d51ee-7ab9-4311-b7b0-b21266eb01d5

Best regards!

f4x
  • 126
  • 1
  • 4
  • 14
  • Open the `TestResults` and check the file's path that MSTest tried to deplyed. But, I think that the problem is on your output directory. Use `"Resources"` instead of `@"Resources"`. – chaliasos Oct 14 '12 at 09:05
  • @Schaliasos, this file isn't contain in `TestResults` directory. – f4x Oct 14 '12 at 13:48
  • No, I mean to [view the TestResults](http://msdn.microsoft.com/en-us/library/ms404662.aspx) for the failed test to see the error. You can see the full path of the file you try to deploy and check that it is correct. – chaliasos Oct 14 '12 at 14:17
  • @Schaliasos, yes, yes it is there nothing :( – f4x Oct 15 '12 at 16:05

3 Answers3

10

Check the properties of the file to deploy (mytest.file).

"Copy to Output Directory" should be set to "Copy Always" (it is set to "Do not copy" by default).

Elena
  • 1,928
  • 1
  • 15
  • 23
  • 1
    Check this post, it is the best troubleshooting description related to DeploymenItem I've seen: http://stackoverflow.com/questions/3738819/do-mstest-deployment-items-only-work-when-present-in-the-project-test-settings-f?rq=1 – Elena Oct 16 '12 at 06:34
  • Thanks for the useful link! It helps me. I understand that led me astray: ugly documentation http://msdn.microsoft.com/en-us/library/ms182475%28v=vs.100%29.aspx for example. – f4x Oct 16 '12 at 08:52
  • Yes, this worked for me. For anyone else reading, make sure it's "Copy Always" and not "Copy if Newer", as the latter also doesn't seem to work. – Scott Whitlock Sep 18 '17 at 11:17
4

Heads up that the path in [DeploymentItem("path")] is case sensitive.

For example: [DeploymentItem("MyTest.file")] is different than [DeploymentItem("mytest.file")] and will cause your deployment item to not be copied over to the TestResults Out folder.

Tyler Angell
  • 151
  • 1
  • 8
0

Yes, marking my "App.config" file as "copy always" fixed it for me.

Mark Conway
  • 483
  • 1
  • 5
  • 10