Skip to main content

Running unit tests using MSTest from console application

There are times when you end up with a requirement like this:
You should be able to run Unit Tests from console application.
And yes, we are talking about MSTests. Well, this is not very complicated using MSTest.exe
Mstest  /testcontainer:[pathToOurTestComponent.dll]
After a few day you end up with a new requirement:
Run Unit Tests using a console application from a machine that doesn’t  
have Visual Studio installed
Using different scripts from internet (like this one:, you end up with a configuration that can be used to run unit tests on machines that doesn’t have Visual Studio.
Mission complete? Yes.
But, you have a problem. Yes, there is a but. What about licensing? Are you allowed to do something like this?
Depends of the person who run your console application. You are allowed to do something like this as long the person who run the console application has a Visual Studio license. This is needed because MSTest component is not allowed to be redistributed based on the current license.
What should I do if clients don’t have a Visual Studio licence?
You could try to use NUnit or other unit test frameworks. There are a lot of frameworks free of charge that can be used.
Below you can find script that extracts the assemblies needed by MSTest if you are using Visual Studio 2013. The script is written using the example written by Wim Coenen for VS2010 (I updated them for VS2013).
The only thing that is missing is the command to extract the registry information needed by MSTest.
@echo off
set here=%~dp0

mkdir mstest
set targetfolder=%here%mstest

set programs=%programfiles%
if exist "%programfiles(x86)%" set programs=%programfiles(x86)%
set vs2013="%programs%\Microsoft Visual Studio 12.0"
set gac2="%windir%"\Microsoft.NET\assembly
set gac1="%windir%"\assembly

echo === Copying from Visual Studio 2013 install folder...
copy %vs2013%\Common7\IDE\mstest* "%targetfolder%"
copy %vs2013%\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Quality* "%targetfolder%"

echo === Copying from %gac1%...
pushd "%gac1%"
dir /s /b *.dll | findstr QualityTools | findstr > %here%tmp.filelist
for /F "tokens=*" %%f in (tmp.filelist) DO copy "%%f" "%targetfolder%"

echo === Copying from %gac2%...
pushd "%gac2%"
dir /s /b *.dll | findstr QualityTools | findstr > %here%tmp.filelist
for /F "tokens=*" %%f in (tmp.filelist) DO copy "%%f" "%targetfolder%"

del tmp.filelist

echo === Done. Check output for errors!
exit /b 0


  1. It should be possible to install MSTest on a server by installing just the test agent ( ) but I'm not sure about the licensing part..

    1. In our case we don't talk about servers. My case was simple users that wanted to run some unit test on their local machines to validate different things.


Post a Comment

Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

Fundamental Books of a Software Engineer (version 2018)

More then six years ago I wrote a blog post about fundamental books that any software engineer (developer) should read. Now it is an excellent time to update this list with new entries.

There are 5 different categories of books, that represent the recommended path. For example, you start with Coding books, after that, you read books about Programming, Design and so on.
There are some books about C++ that I recommend not because you shall know C++, only because the concepts that you can learn from it.


Writing solid codeCode completeProgramming Pearls, more programming pearls(recommended)[NEW] Introduction to Algorithms


Refactoring (M. Fowler)Pragmatic ProgrammerClean code[NEW] Software Engineering: A Practitioner's Approach[NEW] The Mythical Man-Month[NEW] The Art of Computer Programming


Applying UML and Patterns (GRASP patterns)C++ coding standards (Sutter, Alexandrescu)The C++ programming language (Stroustrup, Part IV)Object-oriented programming (Peter Coad)P…