irtual machines can cut time and money out of the software development and testing process, but they aren’t the best choice in every scenario. When should you use virtual machines for developing and testing software, and when should you use a more traditional setup with physical machines? Read on to find out.
|What You Need
|Virtual PC 2004 or Virtual Server 2005
Development and Testing Benefits
Software development typically involves developing and testing for different target environments, but dedicating a physical computer to each environment can be expensive. Not only do you have to consider the initial purchase cost, but physical computers take up space, use power, and require maintenance. Virtual machines can reduce this cost by providing a way to run multiple development and test environments on one physical computer. (Click here to read the sidebar “How Virtualization Works”.)
Another problem with dedicating a physical computer to each environment is that setting up your target environments can be quite time-consuming. In this situation, virtual machines can save you time. If you need to duplicate a particular environment, you can create a library of virtual hard disks that are pre-loaded with specific sets of software. You and other members of your development and test team can clone the disks that you need and quickly replicate a particular environment in a virtual machine.
This type of setup can save lots of time when you need to start over with a clean installation, or duplicate the same environment in several virtual machines (see Figure 1. Virtual Server Status Screenshot).
|Figure 1. Virtual Server Status Screenshot
Figure 1 shows three virtual machines running the same build of BizTalk Server on three different operating systems. You could click one of the thumbnails to access the virtual machine, or else use a Remote Desktop connection. (Note that licensing for software running in virtual machines is pretty much the same as in physical machines, so make sure you have the proper licenses for all of your running software.)
You can also attach virtual machines to physical networks just as if they were physical, or you can create a virtual network for testing different scenarios, while isolating virtual machine network traffic to the host computer. This is useful for patching virtual machines, providing general network access to them, and validating different network scenarios that might be relevant in your software testing.
Development and Testing Uses for Virtual Machines
The following sections describe the different ways that you can use virtual machines for development and testing.
Create a Library of Virtual Hard Disks
As previously mentioned, you can create a library of virtual hard disk (.vhd) files that you and your colleagues can use to “instantly” recreate a particular environment. Under Virtual Server and Virtual PC, you can do this by creating a virtual machine, installing the requisite software on it, and then cloning the .vhd file. You can attach the .vhd file to a new virtual machine, boot it up, and voila: your environment is running on the new virtual machine.
If you want to run more than one virtual machine with the same .vhd on the same network, you must sysprep the virtual machine to prevent network conflicts. For more information and instructions, see my blog post, “Sysprepping a virtual machine“.
Create a Standardized IDE
With your IDE deployed in a virtual machine, you can quickly set up a development environment that meets your company’s standards and even share it with colleagues in your .vhd library. If you work at home, you can install a virtual machine on your personal computer with the corporate “standard” environment so you can connect to the corporate network.
You can also sandbox the virtual machine, isolating it from your personal computer, to satisfy corporate security requirements. This blog post talks about sandboxing a virtual machine under Virtual PC. Also, see the Virtual Server 2005 Administrator’s Guide for information on isolating the network traffic of your virtual machines from your host.
Test New Development and Test Tools
You can try out new tools for software development and testing on a virtual machine without jeopardizing your primary workstation setup. You can set up a .vhd file that has your basic environment installed, copy it, attach it to a new virtual machine, and boot it up. You can then install the new tools and see how they work in your environment.
Perform Functionality Tests
Use the following tips to make it quicker and easier to perform software functionality tests with virtual machines:
- Deploy a variety of destination environments for functionality testing, using minimal hardware (as previously mentioned).
- Set up a library of test environments in virtual machines for rapid deployment (also previously mentioned). Just copy the .vhd file, attach it to a virtual machine, and boot up.
- Run tests and then quickly roll your virtual machines back to a clean state. You can do this with Virtual PC and Virtual Server thanks to a cool feature called “undo disks.” I use it frequently to reinstall builds of software that are under development at Microsoft. To get back to a clean base where I can install the latest build, I do the following:
- Install all of the prerequisites for my software.
- Enable undo disks.
- Install my software.
When I want to go back to a clean base, I turn off the virtual machine and discard undo disks. (For complete information about using undo disks, see the Virtual PC or Virtual Server documentation.)
- Test complex network scenarios without setting up a physical network. Thanks to the flexible virtual networking in Virtual Server, I can create a complete network setup on my test computer and keep all of the network traffic isolated to the physical box. I can even set up a domain, as I describe in this blog post.
What Not to Expect from Virtual Machines
While their benefits all sound ideal, virtual machines do have two main drawbacks: they share physical resources with the host and any other running virtual machines, and they carry some processing overhead. So you can’t expect the same performance from a virtual machine as you do from a physical one. Because they contend for resources in this way, the following are not good uses of virtual machines:
- Performance and stress testing. Your results may not be accurate because the amount of resources available for a given operation can fluctuate.
- Running multiple resource-intensive virtual environments on the same physical computer. Performance will be sub-optimal unless your computer is sized adequately. Your host computer must have the sum of all of the physical resources required by the running virtual machines, plus what the host system needs, plus about another 10 percent for overhead. You’ll have other considerations as well, such as disk I/O requirements. It isn’t possible to give brief, general guidelines, so for details about this, see my blog post “Estimating System Capacity Requirements.”
What does this mean to you? If you’re a developer, limit the number of resource-intensive programs you run on a single computer. If you’re a tester, you shouldn’t try to use virtual machines for stress or performance testing. You should use physical computers for these purposes.