Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. directory path for test method

directory path for test method

Scheduled Pinned Locked Moved C#
csharpvisual-studioxmlquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maddie from Dartford
    wrote on last edited by
    #1

    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.

    H 1 Reply Last reply
    0
    • M Maddie from Dartford

      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.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      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, particularly ExecutingAssembly and CallingAssembly 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.”

      M 1 Reply Last reply
      0
      • H Henry Minute

        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, particularly ExecutingAssembly and CallingAssembly 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.”

        M Offline
        M Offline
        Maddie from Dartford
        wrote on last edited by
        #3

        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.)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups