views:

136

answers:

1

I'm having an issue with Nunit where I cannot find an image file when I run my tests and each time it looks for images it looks in the Nunit folder instead of looking inside the folder where the binary resides. Below is a detailed description of what's happening.

  1. I'm building a binary that is under test which contains the definition for some game elements and png files which will define the sprites I'm using (for sanity sake call it Binary1)
  2. Nunit runs tests from a seperate binary (Binary1Test) executing test methods against the first binary (Binary1).
  3. All tests pass, unless the test executes code in Binary1 which then requires Binary1 to use one of the image files (which are defined via a relative path). When the method is called, Nunit throws a file not found exception stating that it cannot find the file and states it's looking inside of the Program Files\Nunit.net 2.0 folder

So I have no idea why the code is doing this, and to make matters more confusing when I pull up Enviornment.CurrentDirectory it gives me the correct path (the path to my debug folder) and not the path to nunit. Also if I use this instead of using the relative path, my tests will run without issue. So my question is, does anyone know why in the case of loading relative paths from within my binary that nunit decides to use it's directory instead of the directory where the binary is located and where the images are stored? Thanks.

A: 

I'm not sure why this is happening, but wanted to mention something that might help you troubleshoot a little. Do you have any Path Constraint assertions in your tests? It might help you troubleshoot this.

Here's the NUnit.org link for the syntax: http://www.nunit.org/index.php/extensions/docs/2.4/files/index.php?p=pathConstraints&r=2.5.1

Here's an example (from the above link) of the syntax for relative paths. You might want to assert that your relative path is the same as an absolute path and see what is going on. At least you'll have a specific failing test about paths that you'll need to get passing.

Assert.That( "/folder1/./junk/../folder2", 
    Is.SamePath( "/folder1/folder2" ) );
Assert.That( "/folder1/./junk/../folder2/x", 
    Is.Not.SamePath( "/folder1/folder2" ) );
Paddyslacker
By the way, I know my answer isn't a full answer, but wanted to get a code sample in there and it's hard to make those look nice in the comments space.
Paddyslacker