Generate .trx file via code in c#

2.7k Views Asked by At

I was able to generate the unit test result(.trx) file with the help of below link :

Saving unit test results after running tests

Apart from using cmd to generate the .trx file, is there any way to generate the same via code itself.

Thanks in advance.

EDIT

Below is the my sample code :

        System.Diagnostics.Process process = new System.Diagnostics.Process();
        System.Diagnostics.ProcessStartInfo myStartInfo = new System.Diagnostics.ProcessStartInfo();
        myStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        myStartInfo.UseShellExecute = false;
        myStartInfo.FileName = "cmd.exe";
        myStartInfo.Verb = "runas";
        myStartInfo.WorkingDirectory = @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow";
        myStartInfo.Arguments = @"/C VSTest.console C:\UnitTestProject1\UnitTestProject1\bin\Debug\UnitTestProject1.dll /logger:trx"; 
        process.StartInfo = myStartInfo;
        process.Start();

Please note that cmd needs to be run as admin.

1

There are 1 best solutions below

3
On BEST ANSWER

Of course you can run any cmd command using C#. You have to look at the classes in the Process namespace.

Here you have a good document with an example at the end showing different options:

Process.Start MSDN