views:

490

answers:

2

I have a few unit tests that require files from the project to be used to run the unit tests. These files are just images. I need to get the image file using some kind of function within c#, other than pasting the full path like below.

string filePath = @"C:\Users\user1\Documents\Visual Studio 2008\Projects\app1\app1.Tests\Fakes\test_files\test-image.jpg";

I will prefer to do something like:

string filePath = app.path + "\Fakes\test_files\test-images.jpg"

How can I do that?

Thanks!

+1  A: 
bobbymcr
I edited the question, since I did not explain correctly the first time.
Geo
A: 

Just to be clear, this would not be a unit test. A unit test should not rely on the environment. Anything in a database, a file system, etc. should not be used. A unit test should only be used to test a single unit of code. This is due to the fact that if anyone pulls down the source and runs the unit tests (the first thing you should do after getting the source) it will not run. They have to have the environment set up before the tests will pass. These are referred to as integration tests.

That being said, you could set up a variable if it is just in one class or an app.config if it is throughout multiple classes. You could then add a path in there as the default path and use that as "app.path".

J.R. Garcia