tags:

views:

1069

answers:

1

In my winforms application, AppDomain.CurrentDomain.BaseDirectory is set to "C:\Projects\TestProject\bin\Debug\"

In my unit tests it is "C:\Projects\TestProject\bin\Debug" (no final slash). Why is this?

[Edit] @Will : I am asking why the test project's directory doesn't have a trailing slash?

+2  A: 

You may be asking one of two possible questions: Why are they different, or why the test project's directory doesn't have a trailing slash.

Assuming its the first: That's where the code is executing from. When you debug the program, its compiled and the binaries are placed under the project's \bin\debug directory. When you're testing, you're running the test's binaries, which are compiled and placed under the test project's bin\debug directory.

Assuming its the last: Possibly some obscure reason, possibly a bug, or possibly to catch people who are concatenating paths rather than using Path.Combine (naughty naughty!).


Well, I don't know why it's different. Test applications may be run within a custom CLR host; I think this may be the case as test apps do some weird stuff with private accessors that normally aren't allowed within the standard CLR host. I'm only grasping at straws here as I don't have any actual knowledge about how this stuff is actually being coded.

Anyhow, the workaround stands (Path.Combine). Nobody should be concatenating paths, as path delimeters can change.

Will
Yeah, nobody should be concatenating paths (and that wasn't the problem, someone was checking whether the code was running in the IDE by looking for Debug in the path). I found this odd behavior when I was writing Unit Tests that were failing. Mostly a curiosity thing.
Kris Erickson