Thursday, June 27, 2019

How to execute Bat file or command line arguments inside a unit test

             Process proc = null;
            proc = new Process();
            proc.StartInfo.WorkingDirectory = @"C:\Driver\NEW2\";
            proc.StartInfo.FileName = "TrxtoHTML.bat";
            proc.StartInfo.CreateNoWindow = false;
            proc.Start();
            proc.WaitForExit();

WorkingDirectory will change the starting location of the CMD.

Vstest.console.exe not discovering any of the tests


"No test is available in <path> Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again."


My initial plan was to show code coverage on sonar dashboard for a unit test project.

First, I get the .coverage file using below command

%CodeCoverage% collect /output:"C:/XXXXX/VisualStudio.coverage" "C:/Program Files (x86)/Microsoft Visual Studio/XXXXX/vstest.console.exe" "C:/Program Files (x86)/XXXX/XXX.dll"

Then convert it to
coveragexml.

So when I got the project I build it ,done a Nuget reset.
After that point, the test dll file to the vstest.console.exe and try to genarate the .coverage.
However, it says,
"No test is available in my test dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again."
But when i open the solution and execute the project using test explorer at the VS it detect the tests and everything is working fine.

Initial project was developed by visual studio 2017 and at the QA environment we have visual studio 2015.(vstest.console.exe is also came with the VS 2015).

I tryed for several days to resolve this but no luck.
Then I start installing 2017 VS to the QA environment.

Then again do the same thing, Run the command by pointing the test dll and vstest.console.exe, which comes with visual studio 2017.

Bingo it works and it identify the unit tests inside the DLL file.

So the issue was with the wrong vstest.console.exe,




Wednesday, June 5, 2019

Test reporting for MSunit testing

  1. After you have finished your code about test, go build=>rebuild the solution. (no need to use test explorer)
  2. When rebuild succeeds, find the .dll file of your unit test project and copy the path of this file. (In my test, it’s UnitTestProject3.dll)
  3. Open the ‘developer command prompt for VS’. And then type “cd path” command to locate the file which contains the dll file. (The path is what you copy in step2)
  4. After that, type “vstest.console.exe UnitTestProject3.dll /logger:trx”. Then you can see the test result in the window, also you can find the sentence like this “Results file: …path\name.trx”
  5. That is the test result file you want, and you can convert it from xml to HTML by using third-party tools such like trxer. You can type “TrxerConsole.exe TestResultFileName.trx” in cmd to convert it to HTML using trxer.