views:

141

answers:

1

I've got some legacy software that I'd like to involve in an automated unit test (for testing network protocol compatibility) and because this software is old and runs in an outdated environment I'd like to encapsulate it in a virtual machine. What is the best way to control a virtual machine from a Visual Studio unit test? Once I have the vm configured and have saved the state appropriately, I will need to be able to start and stop the vm and possibly launch some programs inside the vm on command.

One consideration I do have is that I'd like for developers not to have to download the vm image if they aren't planning to run this test. The unit test may therefore have to also handle downloading the latest vm image from some location. Our convention is to tag long running tests with a special description so developers will be able to exclude this test during active development.

+1  A: 

The virtual machine platforms provide a scripting API that let you control VMs from the command line. The VMware server docs and a video on Hyper-V Scripting are available.

You will need to include some logic in your build scripts to decide if you should execute the VM code, or just check for the presence of the VM on developers machines.

You may want to check out some of the NAnt and MSBuild task repositories for VM-related tasks to make this easier.

BrianLy
I like the idea of just checking for the image, although I want some build servers to add this test to their schedule automatically when I set the unit test description. I suppose that a build task to retrieve the image from source control would make this easy.
Luke