Ciaran Gallagher
Ciaran Gallagher

Reputation: 4020

How to specify location where test results are saved to?

When automating tests, I would use MSTest.exe, the command-line program. I would pass in a parameter which would specify the location where I want the test result file to save to.

My problem is that I want to be able to run tests from the Visual Studio GUI, and still be able to specify a location for the test results file.

My reason for this is that I am writing a bit of code to read the test result file (since it's in XML format) and to then email the results to a specified email address.

I want my test to get the test result file from the same location regardless of whether I run the test via MSTest.exe or via the Visual Studio GUI.

I know that I can do this in the GUI by selecting the 'Export Test Run Details' option from the 'Test Results' window. I want to know how to do this programmatically, so I can perform the action automatically once the test run has completed.

... alternatively, aren't there classes that should allow me to access the test result information programmatically? I believe there is a TestResult class that might help me, for example, although I'm not quite sure how to use this. I also noticed that the TestContext class has properties such as 'DeploymentDirectory', but they are read-only.

Also, I read elsewhere on-line that with VS2008, you can edit the .testrunconfig file to add the following line in the TestRunConfiguration element:

'<'Deployment userDeploymentRoot="C:\TestResults" useDefaultDeploymentRoot="false" />

But the .testrunconfig file doesn't exist in my solution, and the TestRunConfiguration element doesn't appear in my .vsmdi file.

Any help is appreciated, thanks.

Upvotes: 1

Views: 2693

Answers (1)

chaliasos
chaliasos

Reputation: 9783

You can use a Clean up Script which will copy the Test Results files to a pre-defined directory.

Create a batch with the following code:

::Set the path where the result files will be copied
set TargetDirectory = "C:\..."
::copy the results file
xcopy /s /y "%TestDir%.trx" %TargetDirectory%

Note the %TestDir% variable is autamatically created by the Visual Studio to the qtcleanup.bat which is located to the default test results output directory for each test run.

Your batch file's content will be appended to the qtcleanup.bat so you can use the above variable. You can also open it to see the rest available variables.

After you created your batch file go to visual studio, open the *.testsettings, click on the Setup and Cleanup Scripts and select your .bat file.

It will run every time at the end of the test run.

Upvotes: 1

Related Questions