How to determine the folders used by a Microsoft Visual Studio unit test


You can use the directories used by a Microsoft Visual Studio unit test, by using the TestContext object.

public void GetUnittestFolders()
    Console.WriteLine(string.Format("CurrentTestOutcome [{0}]", TestContext.CurrentTestOutcome));
    Console.WriteLine(string.Format("DeploymentDirectory [{0}]", TestContext.DeploymentDirectory));
    Console.WriteLine(string.Format("ResultsDirectory [{0}]", TestContext.ResultsDirectory));
    Console.WriteLine(string.Format("TestDeploymentDir [{0}]", TestContext.TestDeploymentDir));
    Console.WriteLine(string.Format("TestDir [{0}]", TestContext.TestDir));
    Console.WriteLine(string.Format("TestLogsDir [{0}]", TestContext.TestLogsDir));
    Console.WriteLine(string.Format("TestRunDirectory [{0}]", TestContext.TestRunDirectory));
    Console.WriteLine(string.Format("TestRunResultsDirectory [{0}]", TestContext.TestRunResultsDirectory));




DeploymentDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\Out]

ResultsDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\In]

TestDeploymentDir [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\Out]

TestDir [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21]

TestLogsDir [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\In\L015]

TestRunDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21]

TestRunResultsDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\In\L015]

One Reply to “How to determine the folders used by a Microsoft Visual Studio unit test”

  1. Hello This is great, do you know why Microsoft found it necessary to create a different folder for each time we run the unit tests. We have an automated testing environment and if I run the unit tests after each build, I will end up with hundreds of deployment folders on the build machine.

    It would be nice to set the deployment folder, but have not found a way to override it the TestContext class does not have setters for the deployment folder.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.