When I run a Test Project on Visual Studio I use the code below to access a file inside the test project code folder
var Location = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName ); var FileLocation = Path.Combine( Location ,@'..\..\..\TestProject1\App_Data\data.xml' );
There is another (and better) way?
Are you saying that you’re trying to find the file in the context of a running test itself? If so you should look at the TestContext object, specifically at the TestDeploymentDir property. You should also mark the file as a DeploymentItem.