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: http://mindinthewater.blogspot.ro/2011/02/executing-visual-studio-2010-unit-tests.html), 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
setlocal
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 12.0.0.0 > %here%tmp.filelist
popd
for /F "tokens=*" %%f in (tmp.filelist) DO copy "%%f" "%targetfolder%"

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

del tmp.filelist

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

Comments

  1. It should be possible to install MSTest on a server by installing just the test agent (http://www.microsoft.com/en-us/download/details.aspx?id=38186 ) but I'm not sure about the licensing part..

    ReplyDelete
    Replies
    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.

      Delete

Post a Comment

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

What to do when you hit the throughput limits of Azure Storage (Blobs)

In this post we will talk about how we can detect when we hit a throughput limit of Azure Storage and what we can do in that moment. Context If we take a look on Scalability Targets of Azure Storage ( https://azure.microsoft.com/en-us/documentation/articles/storage-scalability-targets/ ) we will observe that the limits are prety high. But, based on our business logic we can end up at this limits. If you create a system that is hitted by a high number of device, you can hit easily the total number of requests rate that can be done on a Storage Account. This limits on Azure is 20.000 IOPS (entities or messages per second) where (and this is very important) the size of the request is 1KB. Normally, if you make a load tests where 20.000 clients will hit different blobs storages from the same Azure Storage Account, this limits can be reached. How we can detect this problem? From client, we can detect that this limits was reached based on the HTTP error code that is returned by HTTP