13

Visual Studio is generating a lot of empty folders in the TestResults subfolder of C# projects. Is there a way to disable it? I often delete more then 5k of them.

Deploy_UserName 2017-10-31 18_13_17\
Deploy_UserName 2017-10-31 18_57_15\
Deploy_UserName 2017-10-31 19_18_32\
Deploy_UserName 2017-10-31 19_19_47\
Deploy_UserName 2017-10-31 19_20_21\
Deploy_UserName 2017-10-31 19_20_26\
Deploy_UserName 2017-11-02 16_33_32\
Deploy_UserName 2017-11-02 16_34_11\
Deploy_UserName 2017-11-02 16_45_12\
Deploy_UserName 2017-11-02 16_45_39\
Deploy_UserName 2017-11-02 17_09_55\

And this goes like that a few thousand tiems. All are empty.

I'm not sure if they actually slow VS down but I'd rather not have them.

t3chb0t
  • 681

2 Answers2

7

I didn't find a way how to disable it completely but at least an acceptable workaround. It moves them to a location that is more appropriate for them. It goes like that:

  • Create a .runsettings file in your solution directory (you can give it any name - just keep the extension unchanged) with the following contents which will place the TestResults directory in the %temp% location of your machine. If you're not sure where it is, you can always check it in the command-line by calling echo %test% or just pick any other location.

    <?xml version="1.0" encoding="utf-8"?>
    <RunSettings>
    
      <RunConfiguration>    
        <ResultsDirectory>%temp%\TestResults</ResultsDirectory>    
      </RunConfiguration>
    
    </RunSettings>
    
  • You now have to inform your test runner about it.

    • for MSTest users: go to Test > Test Settings > Select Test Settings File
    • for ReSharper users: go to ReSharper > Options > Tools > Unit Testing > Ms Test and pick the Use specific test settings file.

btw, these folders are created always and just won't be deleted if you interrupt the test-runner so it won't clean them up.

(Inspired by Configure unit tests by using a .runsettings file)

t3chb0t
  • 681
1

The TestResults folder can be created by DeploymentItem attributes in your project.

The DeploymentItem attribute will copy any file/directory you specify into the TestResults folder, and instead of running the tests under the bin directory, it will run them under the TestResults directory.

Keep in mind that the DeploymentItem attribute will change the context of all the tests, no matter if you specify it only on one test class. Once I removed all the DeploymentItem attributes from my project, there was no more TestResults folder.

See also: https://stackoverflow.com/questions/883270/problems-with-deploymentitem-attribute

andrew
  • 111