Running UAT and integration tests during a VSTS Build

There are a lots of small suggestions I’ve learned from experience when it is time to create a suite of integration / UAT test for your project. A UAT or integration test is a test that exercise the entire application, sometimes composed by several services that are collaborating to create the final result. The difference from UAT tests and Integration test, in my personal terminology, is that the UAT uses direct automation of User Interface, while an integration tests can skip the UI and exercise the system directly from public API (REST, MSMQ Commands, etc).

The typical problem

When it is time to create a solid set of such kind of tests, having them to run in in an automated build is a must, because it is really difficult for a developer to run them constantly as you do for standard Unit Tests.

Such tests are usually slow, developers cannot waste time waiting for them to run before each commit, we need to have an automated server to execute them constantly while the developer continue to work.

Those tests are UI invasive, while the UAT test runs for a web project, browser windows continues to open and close, making virtually impossible for a developer to run an entire UAT suite while continue working.

Integration tests are resource intensive, when you have 5 services, MongoDB, ElasticSearch and a test engine that fully exercise the system, there is little more resource available for doing other work, even if you have a real powerful machine.

Large sets of Integration / UAT tests are usually really difficult to run for a developer, we need to find a way to automate everything.

Creating a build to run everything in a remote machine can be done with VSTS / TFS, and here is an example.


Figure 1: A complete build to run integration and UAT tests.

The build is simple, the purpose is having a dedicated Virtual Machine with everything needed to run the software already in place. Then the build will copy the new version of the software in that machine, with all the integration test assemblies and finally run the tests on the remote machine.

Running Integration and UAT test is a task that is usually done in a different machine from that one running the build. This happens because that machine should be carefully prepared to run test and simplify deployment of the new version.

Phase 1 – Building everything

First of all I have the phase 1, where I compile everything. In this example we have a solution that contains all .NET code, then a project with Angular 2, so we first build the solution, then npm restore all the packages and compile the application with NG Cli, finally I publish a couple of Web Site. Those two web sites are part of the original solution, but I publish them separately with MSBuild command to have a full control on publish parameters.

In this phase I need to build every component, every service, every piece of the UI needed to run the tests. Also I need to build all the test assemblies.

Phase 2 – Pack release

In the second phase I need to pack the release, a task usually accomplished by a dedicated PowerShell script included in source code. That script knows where to look for dll, configuration files, modify configuration files etc, copying everything in a couple of folders: masters and configuration. In the masters directory we have everything is needed to run everything.

To simplify everything, the remote machine that will run the tests, is prepared to accept an XCopy deployment. This means that the remote machine is already configured to run the software in a specific folder. Every prerequisite, everything is needed by every service is prepared to run everything from a specific folder.

This phase finish with a couple of Windows File Machine copy to copy this version on the target computer.

Phase 3 – Pack UAT testing

This is really similar to Phase 2, but in this phase the pack PowerShell scripts creates a folder with all the dll of UAT and integration tests, then copy all test adapters (we use NUnit for UnitTesting). Once pack script finished, another Windows File Machine Copy task will copy all integration tests on the remote machine used for testing.

Phase 4 – Running the tests

This is a simple phase, where you use Deploy Test Agent on test machine followed by a Run Functional Test tasks. Please be sure always place a Deploy Test Agent task before EACH Run Functional Test task as described in this post that explain how to Deploy Test Agent and run Functional Tests


For a complex software, creating an automated build that runs UAT and integration test is not always an easy task and in my experience the most annoying problem is setting up WinRm to allow remote communication between agent machine and Test Machine. If you are in a Domain everything is usually simpler, but if for some reason the Test Machine is not in the domain, prepare yourself to have some problem before you can make the two machine talk togheter.

In a next post I’ll show you how to automate the run of UAT and Integration test in a more robust and more productive way.

Gian Maria.

Dump all environment variables during a TFS / VSTS Build

Environment variables are really important during a build, especially because all Build variables are stored as environment variables, and this imply that most of the build context is stored inside them. One of the feature I miss most, is the ability to easily visualize on the result of the build a nice list of all the values of Environment variables. We need also to be aware of the fact that tasks can change environment variables during the build, so we need to be able to decide the exact point of the build where we want variables to be dumped.

Having a list of all Environment Variables value of the agent during the build is an invaluable feature.

Before moving to writing a VSTS / TFS tasks to accomplish this, I verify how I can obtain this result with a simple Powershell task (then converting into a script will be an easy task). It turns out that the solution is really really simple, just drop a PowerShell task wherever you want in the build definition and choose to run this piece of PowerShell code.

$var = (gci env:*).GetEnumerator() | Sort-Object Name
$out = ""
Foreach ($v in $var) {$out = $out + "`t{0,-28} = {1,-28}`n" -f $v.Name, $v.Value}

write-output "dump variables on $env:BUILD_ARTIFACTSTAGINGDIRECTORY\"
set-content $fileName $out

write-output "##vso[task.addattachment type=Distributedtask.Core.Summary;name=Environment Variables;]$fileName"

This script is super simple, with the gci (Get-ChildItem) cmdlets I can grab a reference to all EnvironmentVariables that are then sorted by name. Then I create a variable called $out and I iterate in all variables to fill $out variable with a markdown text that dump all variables. If you are interested, the `t syntax is used in powershell to create special char, like a tab char. Basically I’m dumping each variable in a different line that begins with tab (code formatting in markdown), aligning with 28 chars to have a nice formatting.

VSTS / TFS build system allows to upload a simple markdown file to the build detail if you want to add information to your build

Given this I create a file in the artifact directory where I dump the entire content of the $out variable, and finally with the task.addattachment command I upload that file to the build.


Figure 1: Simple PowerShell task to execute inline script to dump Environment Variables

After the build ran, here is the detail page of the build, where you can see a nice and formatted list of all environment variables of that build.


Figure 2: Nice formatted list of environment variables in my build details.

Gian Maria.

Writing a VSTS / TFS task that uses 7zip

Writing a Build / Release task for VSTS / TFS is really simple, but when you need third party software you need to be aware of license issue. As an example I have a small task that uses 7zip under the hood to compress / extract with the fantastic 7zip format.

7zip is good because, even if it uses more processing power to compress files, the result is often really smaller than a standard zip, and this is especially good for build agent that are behind a standard ADSL (300 Kbs upload speed). To create a task that uses 7zip you could simply include 7zip executable in your task, but this can lead to problem for licensing.

Whenever you include executables / libraries in your task you need to check license to verify you have the right to redistribute them.

When you have a task that depends on software that is public, even with a  GNU license, but you do not want to spend too much time to understand complex licensing and / or redistributable right, the simplest path is downloading the tool during task run. Here is the relevant parts of my script

 [Parameter(Mandatory=$false)][string] $sevenZipExe = ".\7z\7za.exe"


if (-not (test-path $sevenZipExe)) 
    Write-Output "7zip not present, download from web location"
    Invoke-WebRequest -Uri "" -OutFile "$runningDirectory\"
    Write-Output "Unzipping $runningDirectory\ to directory $runningDirectory\7z"
    Expand-WithFramework -zipFile "$runningDirectory\" -destinationFolder "$runningDirectory\7z" -quietMode $true 

The solution is really simple, I allow the caller to specify where 7zip is located, then if the 7za executable is not found, I simply download it from the internet a known version and uncompress locally. Then only trick is in the function Expand-WithFramework, that is used to expand the .zip file once downloaded, using the standard classes from .NET Framework.

function Expand-WithFramework(
    [string] $zipFile,
    [string] $destinationFolder,
    [bool] $deleteOld = $true,
    [bool] $quietMode = $false
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    if ((Test-Path $destinationFolder) -and $deleteOld)
          Remove-Item $destinationFolder -Recurse -Force
    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $destinationFolder)

This technique gives me two advantage and a disadvantage. The two advantages are, I’m not including any third party executables in my task, so I have no problem in making it public and the task is really small and simple to run, because it does not contain any executable.  The disadvantage is that the machine running the build should have internet connection to download 7zip if it is not installed locally. Since I’m working mainly with VSTS, all my build machines have internet connection so this is not a problem.

Gian Maria.

Microsoft support for non Windows developers

During Build 2015 conference Microsoft announced Visual Studio Code, a free IDE to develop web, cloud and modern application. The nice aspect of VS Code is that it runs on every platform, here is a screenshot of Code running on a Linux Ubuntu box.


Figure 1: Visual Studio Code running on Linux box

I can now clone a git repository from my Visual Studio Online account and create a first Hello Node Js application. VS Code is not just an editor, and I’m able to debug my node.js code with easy.


Figure 2: Debugging node.js code in Visual Studio Code

VS Code has native support for Git, and I’m able to manage my repository doing push/pull/commit etc, directly from VS Code. Support is still basic, if you need a rebase you should go with CLI, but VS Code is still in preview, so I’m expecting more to come in the near future.


Figure 3: Create a commit directly from VSCode


Figure 4: I pushed changes directly from VS Code in VSO

You can use all VSO feature, if you like you can edit code directly from Web interface if you need to do a quick fix, or if you need to edit a Readme.MD file.


Figure 5: Editing in Web Interface in Visual Studio Online

Thanks to Visual Studio Code, and Visual Studio Online, you can manage your projects from your favourites environment.

Gian Maria Ricci

Team Project Rename

Renaming of Team Projects is one of the most requested feature on Visual Studio User Voice:


Figure 1: Team Project rename suggestion on User Voice

Today, Brian Harry announced new Visual Studio Online Update and it contains this feature, even if it will not be available to everyone at the beginning. For those people that uses TFS on-premise you will have this feature in the upcoming new version: TFS 2015.

I strongly suggests you to have a look at Visual Studio User Voice and give your suggestion, because it is in the radar of Visual Studio Team.

Gian Maria.