Build/Test Issues

Testing methods that load files

Started by stasek27 on 3,284 views

How do i test if a method correctly loads a file that is located in my project folder?

This is how code looks:

	path = Path.Combine(Environment.CurrentDirectory, "Ranges", "test.range");


But NCrunch looks in a different folder and I get an exception

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\[removed]\AppData\Local\NCrunch\5916\83\VS\ProjectName\CommonsTests\bin\Debug\Ranges\Holdem\3B16.range'.

How do I make Ncrunch to look in the [ProgramOutputFolder]\Ranges\Holdem\ folder?




Hi, thanks for posting!

The correct behaviour is for NCrunch to look up a copy of the file inside its workspace. In this way, it works completely in isolation from your code.

With this in mind, NCrunch is already looking in the right place. The problem is that the file hasn't been copied there.

There are a few ways you can handle this. If your code relies on a file that isn't included in any project file, NCrunch considers this to be an 'Implicit dependency'. You can read more about implicit dependencies and how to resolve them here - http://www.ncrunch.net/documentation/considerations-and-constraints_implicit-file-dependencies.

If for some reason you don't want NCrunch to copy the file to the workspace (for example, if it's really big and copying it just isn't resource efficient), the NCrunch.Framework.Environment.GetOriginalSolutionPath() can be used to find your original solution when running inside NCrunch's test environment.

This has worked. Thanks.

Post a reply

Log in to reply.