How to run the same test in different Lab Environments?

I will try to address today a common query by lot of users of Visual Studio Lab Management on how to correctly run tests in different Lab Environments.

This requirement can be achieved by making the test code read the Server names/other configuration through environment variables:

  1. The following post by Gautam explains the changes that will be required in the test code:

  2. Extra requirement from VS Lab Management is that, the environment variable binding should be done using the following code:

    Environment.GetEnvironmentVariable("TestServer", EnvironmentVariableTarget.Machine);


Now, we need to configure our test machines to have the correct values of the environment variables, for achieving this we can do:

  1. Set this environment variables on the test execution machine before we trigger a test run manually. This approach can be used in cases where the values will not change frequently or from environment to environment.


  1. The values to the environment variables can be set as part of Deploy of Lab E2E Workflow. For doing this we add a deployment script to run the following command on test execution machine:

    cmd /c setx /M TestServer $(InternalComputerName_testServerName)

Please refer for information about Deploy and macros of Lab E2E workflow.


Note: The capability to run Lab E2E Workflow is only available for virtual environments in VS 2010. It is available for both Standard (Physical) and SCVMM environments in VS vNext.