Automating Software Testing with Microsoft Hyper-V
The first copy command copies the application's setup file to the remote virtual machine, and the second line starts the msiexec utility (the Windows Installer utility) to install the MSI package silently. This is done with the help of the PSExec utility (which is a 32-bit application, so it is located in the x86 version of the Program Files folder). Of course, if your application does not require installation, you could simply replace these lines with an appropriate copy command.
The third line again uses PSExec to remotely start the tested application on the virtual machine. Here, you also could specify whatever parameters might be needed for the application to automatically take the required actions.
Finally, you could collect the results. For instance, if your application logs to a text file, you could simply copy the log back for the testers to investigate:
$log_name = "T:\TestReports\MyApplication Log " + [System.DateTime]::Now.ToShortDateString() + ".log"; copy \\192.168.0.123\TestLocation\MyApplication.log $log_name
With these lines, you take the current date from the System.DateTime class (as you see, you can construct .NET class instances directly from the PowerShell prompt), and then combine it to a full log file path. This way, daily logs will not overwrite older logs.
After all is done, you optionally could compose an SMTP message, write an entry to the Windows Event Log, or otherwise signal to the testers that the application has finished running. Alternatively, you could simply schedule the testing to happen at nighttime, and simply view the log file in the morning.
When virtualization in the PC world was new, software developers were one of the first group of users to adopt virtual machine technology. Thus, it is no surprise that virtualization is used heavily in software testing. However, testing can be a time-consuming task if done completely manually.
With Microsoft's Hyper-V virtualization technology, you are able to step up the ladder in virtualization features, and at the same time make your testing more automatic. For example, if you are using Visual Studio Team Foundation Server (TFS) and its Team Build feature, you could automate both the application building and testing in a single MSBuild script, and make all this happen with a click of a button.
Because Hyper-V easily supports multiple virtual machines and dozens of checkpoints (snapshots), you can automate testing of your applications. Automating user interface testing is, of course, more difficult, but even with these applications, being able to automatically configure the virtual testing environment can save a lot of time.
Let these scripts be your starting point in automating your software testing with Microsoft's Hyper-V. Thanks go to Janne Pohjala from Microsoft Finland for helping me find the hardware to test Hyper-V on. With that, happy testing!
Sidebar: Automating Virtual Server and VMware Environments
If you are currently using Microsoft Virtual Server or VMware's Workstation or Server virtualization products and you want to automate your virtual machines with those, you are not out of luck. Both Virtual Server and VMware Workstation offer an automation API that can be used to do similar tasks already shown in this article with Hyper-V.
To get started, check out Microsoft's Virtual Server COM API (callable from C# or any other .NET code) and VMware's VIX API. VMware's API is C based (native, or also known as unmanaged code), but you could also call it from .NET applications.
As for the Virtual Server API, check out the IVMVirtualServer and IVMVirtualMachine interfaces documented on MSDN. For VMware's VIX API, visit www.vmware.com/support/developer/vix-api.
- Hyper-V home: http://www.microsoft.com/windowsserver2008/en/us/hyperv.aspx
- System Center VMM home: http://www.microsoft.com/systemcenter/virtualmachinemanager/en/us/default.aspx
- PowerShell home: http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx
- The PSExec utility: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
About the Author
Jani Järvinen is a software development trainer and consultant in Finland. He is a Microsoft C# MVP and has written dozens of magazine articles and three books about software development. He is a group leader of a Finnish software development expert group named ITpro.fi. His frequently updated blog can be found at http://www.saunalahti.fi/janij/. You can send him mail by clicking on his name at the top of the article.
Page 4 of 4