directory path for test method
-
Hello, I am using
string exePath = System.Windows.Forms.Application.ExecutablePath;
string myFilePath = Path.GetDirectoryName(exePath) + Path.DirectorySeparatorChar + "MyFile.xml";to get working path of a file and it works fine when i run the application with VS2008. I have written test method "[TestMethod]" to test a fuctionality which uses the above application path but my test result is failed because if i run test case then the excecutable path refers to visual studio env exe and my file is not present over there. I don't want to hard code the file path. Please tell me how can i make my test case successfull or get the correct application path. Thanks in Advance.
-
Hello, I am using
string exePath = System.Windows.Forms.Application.ExecutablePath;
string myFilePath = Path.GetDirectoryName(exePath) + Path.DirectorySeparatorChar + "MyFile.xml";to get working path of a file and it works fine when i run the application with VS2008. I have written test method "[TestMethod]" to test a fuctionality which uses the above application path but my test result is failed because if i run test case then the excecutable path refers to visual studio env exe and my file is not present over there. I don't want to hard code the file path. Please tell me how can i make my test case successfull or get the correct application path. Thanks in Advance.
You may be able to use the
Assembly
class to get the information you require. Here is the example from the documentation:Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);Look up the documentation for
Assembly
, particularlyExecutingAssembly
andCallingAssembly
to decide the best way to proceed for your circumstances.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
You may be able to use the
Assembly
class to get the information you require. Here is the example from the documentation:Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);Look up the documentation for
Assembly
, particularlyExecutingAssembly
andCallingAssembly
to decide the best way to proceed for your circumstances.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Thanks Henry, It is returning the path as "file:\C:\....\\....\TestResults\user_UKNML2009-10-16 16_39_37\Out". I need debug or application executable path. (If i do some modification in code to reach up to the required path from the assembly path then it will not work for actual application output.)