Wednesday, November 15, 2017

VSTest.Console.exe TestContext.WriteLine messages

I had a situation today where I needed to run some automated tests (written using the Visual Studio UnitTest framework) on an Azure App Service Web App (to reduce latency to the test database, which is an Azure SQL Database).

My first step was to get VSTest.Console.exe (and its dependencies) into the Web App. I am using Visual Studio 2017, so I zipped this entire folder:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow

Using Kudu/SCM, I created D:/home/vstest and uploaded/unzipped the file.

Next I copied up my *.runSettings file and my test assembly (with dependencies). With all of the necessary files in place, I ran this command line (also via Kudu/SCM) based on the documented command line options for VSTest.Console.exe:

D:/home/vstest/vstest.console.exe D:/home/product/EQuIS/Application/bin/EarthSoft.EQuIS.dll /Settings:D:/home/_Test/sql.runSettings /Tests:LoadEddPerformanceTest 

That seemed to work fine - except that it would not show me my TestContext.WriteLine messages. Within the test code itself, I was using TestContext.WriteLine to output some timing information.

After much trial and error, I finally found the undocumented "/Diag:{filename}" option. That option will output a lot of detailed information into the given filename, including the TestContext.WriteLine messages:

D:/home/vstest/vstest.console.exe D:/home/product/EQuIS/Application/bin/EarthSoft.EQuIS.dll /Settings:D:/home/_Test/sql.runSettings /Tests:LoadEddPerformanceTest /Diag:D:/home/TestResults/output.log

No comments:

Post a Comment