14 February 2013

Hosts file editor to switch an environment

In software development, the built code will be promoted to higher environments to test the quality. There could be a different number of the environments based on the requirements. However, the commonly seen such environment across different projects are DEV, QA, STAGE, Pre Prod and PRODUCTION.

We can hit the Web services or web application hosted on different environments by changing the host entries on the test machine. But changing the host entries is time-consuming and error-prone. Typically testers/QAs will be changing these host entries to change the environments around 2 to 3 times in a day. This task is boring. So to get rid of this mundane task created small windows client application utility.

User interface:

Hosts file editor to change the environments

Prerequisites:

The Environment Changer Tool has prerequisites for keeping host entries in the hosts file for each environment:

  1. All host file entries for a given Environment has to be present under it. This anyway you would have already following it.For example if you have a DEV environment and have the below hoist entries, they all should like below in your host entries.

    #DEV
    111.222.333.444 webservices
    121.222.333.445 apiservices

    #QA
    #112.222.333.444 webservices
    #122.222.333.444 apiservices

  2. The different environments will be configured in the application config file(app.config file). Each environment should be separated by semicolon(;).
  3. The hosts file will located more or less at "C:\WINDOWS\system32\drivers\etc". However if need, this settings can also be set in config.
  4. The Tool is windows form application built on .NET 2.0; So the .NET framework should be present on the machine.

Host file editor application config file:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="Enviroments" value="LOCAL;TEST;UAT"/>
    <add key="HostFileFullName" value="C:\Windows\System32\drivers\etc\hosts"/>
  </appSettings>
</configuration>

That's it.The tool is really simple. Just keep your host entries as per the prerequisites and you will find the tool really helpful. By using this tool you can save around 2 minutes of time, whenever you want to change environment.

The tool now can be downloaded from codeplex