by Joakim

Delete ReSharper Test Results on “Clean Solution”

On my local dev machine, I can see no reason for keeping old test results (on a build server it’s another matter completely though). You usually run your tests quite often when developing, and thus you get a lot of “test result”-folders cluttering up your hard drive. Some test runners have options for configuring how many old test results you would like to keep, but this is not the case for ReSharper’s test runner (afaik).

To remedy this I’ve created a new target in the project file for my test project, that will delete the test result folder when I right-click the solution Visual Studio’s solution explorer and select “Clean Solution” (or on a project and select “Clean”). By default ReSharper creates the test results in “<ProjectFolder>/bin/<Configuration>/TestResults”, you can however change this (and therefore need to modify the config below accordingly).

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  .
  .
  .
  <PropertyGroup>
    <TestResultsFolderPath>bin$(Configuration)TestResults</TestResultsFolderPath>
  </PropertyGroup>
  <Target Name="AfterClean">
    <RemoveDir Directories="$(TestResultsFolderPath)" Condition="Exists('$(TestResultsFolderPath)')" />
  </Target>
</Project>

This target will check if there is a test results folder, and if there is, it will delete it (and it will only run when you clean the solution/project).

If you have more than one test project (i.e. one for unit tests and one for integration tests, etc.) you need to add it the project file for each project. Also beware that adding this target will affect everyone working on the project, not just you!

This solution should work for other test runners as well, just modify the “TestResultsFolderPathabove to reflect where the test results are created.

As I said in the beginning, some test runners allow you to configure how many old test results should be kept at any time, making this a non-issue. E.g. if you’re using the test runner found in Visual Studio out of the box, you could go to “Tools –> Options –> Test Tools –> Test Execution” and specify a number for the “Limit number of old Test Results to”-setting.

  • thorhalvor

    Smart! Never thought of doing this in the “AfterClean”.
    Normally though, I end up with a Clean.bat file for my developer machine deleting all all binaries in bin/debug obj/debug bin/relase etc and then also the TestResults folder. In the bat file you can run code like: Forfiles -pC:projectsTestResults -s -m*.* -d-5 -c “cmd /c del /q @path” -which will delete all files older than 5 days for example.
    To easier clean everything I normally set up Resharper to have one folder for all TestResults and not within every project.

  • http://www.degree.no Joakim

    @thorhalvor Yes, having a script to do it is a good solution as well, especially if not everyone on the team want the behavior with deletion on clean (since, as I pointed out, putting this functionality in the project file will affect everyone working on the project, not just yourself).