tags:

views:

37

answers:

2

As above really, I have some integration tests that use files from a relative file path. To help picture it here is the file structure:

/Dependencies
/VideoTests/bin/release/video.dll
/SearchTests/bin/release/search.dll
/OtherProjects

The GUI is running the tests from the root, however when TeamCity runs the tests it is running the tests from each test dlls bin directory. Now I don't mind which one I can get to follow the other but I do need them to be the same otherwise my relative paths just won't work!

Any ideas?

P.S. Using TeamCity 5.0 and NUnit 2.5.

A: 

Have you made sure that both TeamCity and NUnit are using the same working directory when starting the application?

And if they aren't, you could adjust the current directory in the test code.

phsr
Well I've tried to look for such a setting but I'm not having much luck. TeamCity seems to run the tests from the location of the assembly, and I can't find a setting to override this. NUnit seems to run it from the path that the GUI was opened from and I can't seem to find a setting to tell that to run the tests from the assembly folder. I just seem to be missing one tiny setting.
John_
Couldn't you just set the Environment.CurrentDirectory in the setup phase for each test?
phsr
Well that's why I want the current directory in the first place, because I don't know where the DLL is in the file tree. Assembly location mentioned above sounds like the ticket to me as that will always give me the path to the assembly executed.
John_
I would then use popester's suggestion to use the Assembly.GetExecutingAssembly().Location. I use the same method to be able to load plugins for a program I developed
phsr
A: 

You probably don't want to rely on CurrentDirectory. I'd suggest reading the doc, but the main point you'll want to take away is that the CurrentDirectory is where the .exe was started from: it could be any path in the system. For example, let's assume your users add your .exe (or whatever .exe uses your DLLs) to their path. They could then navigate to c:\foo\bar and start the .exe from there, which would set the CurrentDirectory to "C:\foo\bar" and you may not be able to deal with that.

I think it would be preferable for you to rework whatever you're doing so you don't rely on CurrentDirectory. What problems are you encountering by relying on CurrentDirectory right now?

popester
I'm trying to get the relative path to a file in the Dependencies folder. My only way of doing this (without adding a full path which I definately don't want) was to use the CurrentDirectory.
John_
If you're intent on using CurrentDirectory then your lookup to the Dependencies folder will have bugs in production. I would investigate out Assembly.GetExecutingAssembly().Location
popester
Ah ok, I think I can get that to work. I'll give it a go and get back to you.
John_