0

I'm running unit tests with Visual Studio which takes this as the command on the cmd:

vstest.console.exe C:\Desktop\Project\UnitTests\Debug\UnitTests.dll /Logger:trx

Once that executes it generates a .trx file (visual studio test result file). Next I want to take this file and run it through a program called trx2html that will generate a html file from it that is in a readable format. The command for this is:

trx2html.exe trxResultFile

This seems fairly simple but I can't seem to get the second part to work. My problem is that the first program generates a filename so I can't just type this filename after the trx2html.exe.

Here is my bat file so far:

@echo %1

SET ProjectPath=%1
SET VsTest=vstest.console.exe %ProjectPath% /Logger:trx
SET TestWindowPath="C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow"
SET TestResults="C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TestResults\"

cd /d %TestWindowPath%

pause

%VsTest%

trx2html.exe "%TestResults% | %VsTest%"

Any help would be appreciated, thanks in advance.

manjesh23
  • 369
  • 1
  • 4
  • 21
DaveS
  • 43
  • 4
  • So you don't know what the file name looks like which is used by the first tool? how do you want to find the created file -- just per file extension `.trx`? which location? what if there are more than only one? – aschipfl Jan 07 '16 at 13:12
  • It is stored in the TestWindowPath shown above, they are saved in format: username_computername_date_time.trx – DaveS Jan 07 '16 at 13:16
  • 1
    Okay, that means you need to look up the most recent `*.trx` file, right? if so, you could either parse the file name and extract the date portion, or to use the file (modification) date, which I would go for: `for /F "eol=| delims=" %%F in ('dir /B /A:-D /O:D "%TestWindowPath%\*.trx"') do set "FILE=%%~fF"` (this sets variable `FILE` to the full path of the most recent file) – aschipfl Jan 07 '16 at 13:18
  • Okay thanks, I'll take a look at that. – DaveS Jan 07 '16 at 13:20
  • Got it to work with a similar solution, thanks! – DaveS Jan 07 '16 at 13:48
  • You might provide your solution as an answer to show what you did; you may even mark it as accepted later... – aschipfl Jan 07 '16 at 14:01

1 Answers1

0

This is the solution I used:

cd /d %TestResults%

for /f "delims=" %%x in ('dir /od /a-d /b *.*') do set RECENT=%%x
echo %RECENT%

SET trx=trx2html.exe "%RECENT%"

%trx%

and the whole program:

@echo %1

SET ProjectPath=%1
SET VsTest=vstest.console.exe %ProjectPath% /Logger:trx


SET TestWindowPath="C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow"

SET TestResults=C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TestResults\

cd /d %TestWindowPath%

%VsTest%

cd /d %TestResults%

for /f "delims=" %%x in ('dir /od /a-d /b *.*') do set RECENT=%%x
echo %RECENT%

SET trx=trx2html.exe "%RECENT%"

%trx%
DaveS
  • 43
  • 4