How to specify location where test results are saved to? - visual-studio-2010

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.

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.

Related

How to call a custom build tool through a batch file

While trying to setup the Cap'n Proto compiler as a custom build tool in Visual Studio 2017, I came across a curious behavior, it only seems to work when called directly and not through a batch file.
What I first tried was, for each .capnp file, set the following Custom Build Tool settings:
Command line: "$(SolutionDir)run_capnpn.bat" compile -oc++ "%(FullPath)"
Description: Executing capnp.exe on %(Identity)...
Outputs: %(Identity).c++;%(Identity).h
I made the batch file because I wanted to avoid polluting my %PATH% with the capnp folder, this is what it contains:
#echo on
echo %*
SET PATH=%PATH%;C:\GitHub\capnproto\bin\c++\src\capnp\Debug
start /wait "" capnp.exe %*
exit /b %errorlevel%
However, with this setup the Custom Build Tool was only called on 1 of the 5 capnp files in my solution (all 5 files had exactly the same settings). I know this because only one pair of generated files appeared and only one message appeared in my build log.
Even weirder, if I compiled again it would do the next file, and on the following compile it would do another file. In all, it would take 5 compiles (one per file) before it considered everything to be fully built and stop calling the custom build tool.
After much trial and error and some help from other programmers on Discord, I tried adding capnp.exe to my path and call it directly (instead of going through the batch file) so for each capnp fil I changed the command line setting to:
capnp.exe compile -oc++ "%(FullPath)"
and now it all builds correctly. Is it possible to call a custom build tool through a batch file? and if so how?

Is it possible to run a batch file as part of the Run command (i.e. F5)?

I'd like to execute a batch file when I run the solution which will prepare the environment that I'm deploying to. I want this to run first thing when I hit F5 before anything else happens. Is this possible? If so, how?
In the project's property pages, under Debugging tab, set the proper value for Command option. Default value is $(TargetPath), which will run the output executable. Just specify your batch file there.
You will have to run the executable on your own in this case. I suggest passing $(TargetPath) as a parameter to your batch script and then executing the parameter.

debugging with visual studio using redirected standard input

I am debugging c++ console application with Visual studio. I exhausted of inserting the same input every time I debug this program. I would like to use the same input more times.
I do this without debugging in command line with command: Program.exe < 1.in
Is it possible to use debugging with standard input redirected from file???
I already tried looking in to procejt properties. I tried setting Command to $(TargetPath) < 1.in instead of $(TargetPath).
I also tried setting Command Arguments to < 1.in. Niether of these method worked.
I am using Visual Studio 2012. But this is probably same in all versions of studio.
This is a supported debugging scenario. You do have to make sure that the debugger can find the file. Leave the Command setting at $(TargetPath). A possible value for the Command Arguments setting is:
< "$(ProjectDir)test.txt"
if the input file "test.txt" is located in the project directory. Or type the full path of the file to be sure. The MSDN article that describes this feature is available here.
I just create a file called stdin.txt in the project
1) set the Build Action to Content
2) Copy to Ouput Directory: Copy if newer
Then when you build stdin.txt is copied to the same folder as the executable.
Then in project properties debug|command line arguements enter the following
< stdin.txt
There is no need to use a path macro
If you don't want to mess with the the path you can add a new file with a right click on the source files folder in the solution explorer and then paste to it the content from the wanted file. And then change the command argument to the new file name.

Possible to Auto Open file in Visual Studio

I currently use the following cleartool command using Visual Studios External tool interface:
Command: \installationpath\cleartool.exe
Arguments: annotate -nheader $(ItemPath)
Initial directory: $(ItemDir)
I do use the output window. Which will let that command print out the location of the .ann file it produces. I'm wondering if there is a way for Visual studio to auto open that produced file?
In this case its not a huge hardship to copy the location and open the file. I'm just always looking for ways to make things easier.
Using just one external tool, you wouldn't be able to execute cleartool, and to open a file (generated from the cleartool command).
You can open a file from a Visual Studio External Tool as explained here, but that wouldn't execute cleartool.
So I would recommend executing a script (.bat, .cmd, .vbs) in order to:
do the cleartool command you want
open the generated file.
You would pass to this script no only $(ItemPath), but also, depending on where it is generated, $(ItemDir), or $(ProjectDir), or $(SolutionDir), or $(TargetDir).

Passing custom arguments as Command-line argument by running the MsTest.exe command prompt or via bat file

My need is to Pass a custom arguments/Parameter to the unit test when running via the MsTest in the Command-line.
The argument must be as command line argument and need to access the param value inside the test class or method.
The MSTest command line does not support this option. Please look for a way to:
create a text or configuration file
start mstest
read that file from within your test.
A similar suggestion is posted in MSTest Command Line Settings.
In your comment to kroonwijk you said that you're trying to specify a particular config file to use in the test run. The way that I've handled this in the past is to create some App.config transforms (e.g., App.Test.config) where the "Test" part matches a configuration name that I set up in the configuration manager. Then, when I do a build with that particular configuration, the appropriate transformations are applied and the resulting config file has the values that I need for that environment.

Resources