views:

33

answers:

1

Hi, I am currently experimenting with TFS, and I really like it.
One small question, regarding test files:

I have a directory with some demo TXT, images, dirs... These are used during tests, so up until now, the path was hardcoded to a folder on my computer. Now I need to change this, of course, the TFS need access to the files too.

My idea was to place them inside the folder of my solution, I currently have roughly this structure:

  • Solution Folder
    • mysol.sln
    • SomeProjectDir
    • OtherProjectDir
    • _LIB for external .dll
    • _DEMO_FILES for test files

The whole solution folder is under source control. Would you do it the same way? How is the best and elegant way to get the "real" path of the folder for usage in unit tests? Using the execution path an cutting away the rest? Do test files belong under source control?

Thanks for any input,
Chris

EDIT: Beside the tip given in the answer, please be aware that with testing there are some pitfalls with this. The test is executed in a different folder (often named after some timecode), the testfiles do not get copied there automatically. Even if they are set to copy always.

The solution is to either add the files manually by using a attribute called DeploymentItem in the unit-test, or, in my opinion much better, adjust the Local.testsettings and add the folder there. Keep in mind, the folder itself will not be added, so you need to do it one level higher..

You will understand what I mean if you try it. Or search for DeploymentItem on google

+3  A: 

Hi,

test files are part of your project, so there is NO reason to keep them out of the version control system. You should commit to the version control system everything that is needed to build, test and run your system, including 3rd party libraries, config files, test files, and even arguably documentation. Please note that most of these things should be part of your Visual Studio solution as well.

In my projects usually I try to have all my resources as Embedded Resource, so that I don't need to figure out the path, they are compiled into the assembly. If for some reasons I can't go this way, I would make the build copy them to the output folder (so mark them as copy always in VS) and then use relative paths.

Grzenio
Thanks, thought so... Any tip on how to include empty folders. I think VS will not copy them to the output dir, I could have a placeholder.txt which I delete before testing. I need empty folders for some tests (to test that empty folders do not create a problem :-)
Christian
Or you could have a post-build script that will just create the folder.
Grzenio
Yes, also a good idea... I think I will even do it in a test setup. I do not like build scripts, especially when using TFS. At the moment, everything works nicely, not sure how it behaves with scripts, had some issues with these before (script fails, build is marked as failed, and so on...) I think I like a failing test better..
Christian
Cool, creating it in the test setup is actually the best idea by far - it will be obvious for your colleagues where are these folders coming from and why you need them!
Grzenio