, , , , , , , ,

Last week I was tasked with finding out whether automated test runs can be scheduled, so they can be started without anyone being in the office. A few minutes research told me a few others were stuck on this problem. There was the option of using MSTest to run a set of projects from a list, but Visual Studio 2013 replaces this feature with a ‘Playlist’, and unfortunately there isn’t a way of directly launching this from outside the IDE. Well, the following is a little workaround that I hope others would find useful.

The Visual Studio installation includes a command line program called vstest.console.exe, which (to my surprise) is capable of reading the test script instructions from a project DLL. It is found at C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe.
With a little setting up, it’s possible to use the Windows Task Scheduler to launch this. It’s awkward if you want it to launch a sequence of projects, though, so we also need a batch script.

First, create a container directory and copy the DLL files (/bin/release or /bin/debug) for each project into it.


Then create the batch script to start vstest.console.exe and point it to the DLLs. Although the script could probably be written straight into the Task Scheduler, most people would want to re-use it for other things. It should look something like this:


All that remains is to configure the Windows Task Scheduler to run the batch script at a pre-determined time.


It does actually work while the computer is ‘sleeping’, and the computer will remain locked. When done, the output normally displayed in Visual Studio’s Test Explorer window will be dumped to a file in the container directory.