is it possible to include files to run with unit tests?

my unit tests use reflection to load files for testing. i've tried to get the files included with the unit test by selecting "copy to output" as a property in the solution. i've made a hack in the code that loads the files...

string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

string resharperFile = Path.Combine(filePath, "__AssemblyInfo__.ini");
if (File.Exists(resharperFile))
{
string iniContents = ReadFileFromDisk(resharperFile, Encoding.Unicode);

int filePathStart = iniContents.IndexOf("file:///") + "file:///".Length;
int filePathLength = iniContents.LastIndexOf('/') - (filePathStart);
filePath = iniContents.Substring(filePathStart, filePathLength);
filePath = filePath.Replace('/', Path.DirectorySeparatorChar);
}

// otherwise filePath remains unchanged, since the TestDriven.NET plugin uses the original location and the files I need are in the solution.

is there an elegant way to do this?

2 comments
Comment actions Permalink

The best way IMHO is to build all your projects to the same directory, and
then instruct ReSharper to run unit tests from that directory

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"brian zinn" <brazinn@yahoo.com> wrote in message
news:6354357.1156954522138.JavaMail.itn@is.intellij.net...

my unit tests use reflection to load files for testing. i've tried to get
the files included with the unit test by selecting "copy to output" as a
property in the solution. i've made a hack in the code that loads the
files...

>

string filePath =
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

>

string resharperFile = Path.Combine(filePath, "__AssemblyInfo__.ini");
if (File.Exists(resharperFile))
{
string iniContents = ReadFileFromDisk(resharperFile, Encoding.Unicode);

>

int filePathStart = iniContents.IndexOf("file:///") + "file:///".Length;
int filePathLength = iniContents.LastIndexOf('/') - (filePathStart);
filePath = iniContents.Substring(filePathStart, filePathLength);
filePath = filePath.Replace('/', Path.DirectorySeparatorChar);
}

>

// otherwise filePath remains unchanged, since the TestDriven.NET plugin
uses the original location and the files I need are in the solution.

>

is there an elegant way to do this?



0
Comment actions Permalink

thanks for your help. i'll work my way through the documentation to see how setting directories is accomplished.

0

Please sign in to leave a comment.