How to get Directory while running unit test

后端 未结 14 864
余生分开走
余生分开走 2021-02-02 05:07

Hi when running my unit test I\'m wanting to get the directory my project is running in to retrieve a file.

Say I have a Test project named MyProject. Test I run:

<
14条回答
  •  难免孤独
    2021-02-02 05:24

    Usually you retrieve your solution directory (or project directory, depending on your solution structure) like this:

    string solution_dir = Path.GetDirectoryName( Path.GetDirectoryName(
        TestContext.CurrentContext.TestDirectory ) );
    

    This will give you the parent directory of the "TestResults" folder created by testing projects.

提交回复
热议问题