6

I'm working on an MVC site with an image upload capability and I want to write a test that will upload an image.

I made an image called TestImage.jpg and set Copy to Output to be "Copy if Newer". In my test I try to load that with the following code:

System.Drawing.Image testImage = System.Drawing.Image.FromFile(@"TestImage.jpg");

Shouldn't the "Copy to Output" copy it to the same directory where the test is running? If not, how can I find out where it was copied to? Best would be some kind of project root relative path so I can feel free to move the solution around without this breaking.

aygul
3,27512 gold badges40 silver badges42 bronze badges
asked Sep 28, 2009 at 22:37

2 Answers 2

16

In MSTest, the framework copies all .dlls to a folder called TestResults. Unfortunately, it only copies .dlls, .pdbs and .configs from the output folder to the TestResults folder, so your files are not being copied.

To copy those files, you will need to either

  • add the DeploymentItem attribute to the test(s) in question
  • edit your .testrunconfig file by adding the appropriate files in the Deployment tab

A better alternative is to embed the test-specific files in the test as an embedded resource and then read them directly from the resource stream.

answered Sep 28, 2009 at 22:49
1
  • thanks - the "add the DeploymentItem attribute to the test(s) in question" worked Commented Oct 14, 2009 at 7:39
1

in the solution explorer Under solution items double click LocalTestRun.testrunconfig go to deployment and add the image

http://img17.imageshack.us/img17/5219/sanstitrelca.jpg

answered Sep 28, 2009 at 22:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.