Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a virtual machine with automated tests?

I am attempting to setup automated tests for our applications using a virtual machine environment.

What I would like to have is something like the following scenario:

  1. Build server is automatically triggered to start an automated test for the application
  2. A "build" script is then run which consist of:
    1. Copy application files and a test script to a location accessible by the VM
    2. Start the VM
      1. In the VM, a special application looks in the shared folder and start the test script
      2. The tests script do its job, results are output to shared folder
      3. Test script ends
      4. The special application then delete the test script
      5. The special application somehow have the VM manager close the VM and revert to the previous snapshot
    3. When the VM has exited, process the result and send to build server.

I am using TeamCity if that matters. For virtual machines, we use VirtualBox but we are open to any other if needed.

Is there any applications/suite that would manage this scenario?

If there are none then I would then code it myself, should be easy but the only part I am not sure is the handling of the virtual machine.

What I need to be able to do is to have the VM close itself after the test and revert to a previous snapshot since I want it to be in a known state for the next test.

Any pointers?

like image 517
Stécy Avatar asked Jun 15 '11 14:06

Stécy


People also ask

What is VM in testing?

What is Virtual Machine Testing? Virtual Machines (VMs), often emulators and simulators, are essentially software that emulates devices (other than the physical device it is running on) so that users (devs or testers) can use it to check how a specific software works on a particular device.

Can Jenkins run automated tests?

Runs Automated Test Suites: Jenkins provides plugins for various test frameworks like Selenium, Cucumber, Appium, etc. These can be integrated into CI pipelines to run automated tests for every build.


2 Answers

I have a similar setup running and I chose to use Vagrant as its the same thing our developers where using for normalizing the development environment.

The initial state of the virtualmachine was scripted using puppet, but we didn't run the deployment scripts from scratch on each test, only once a day.

You could use puppet/chef for everything, but for all other operations on the VM, we would use Fabric scripts, as they were used for the real deployment too, and somehow fitted how we worked better. In sum the script would look something like the following:

vagrant up   # fire up the vm, and run the puppet provisioning tool
fab vm run_test  # run tests on vm
fab local process_result  # process results on local shared folder
vagrant destroy  # destroy the vm

The advantage is that your developers can also use vagrant to mimic your production environment without having to take care of that themselves (i.e. changes to your database settings get synced to all your developers vm's wherever they are) and the same scripts can be used in production too.

like image 93
ashwoods Avatar answered Sep 22 '22 15:09

ashwoods


VirtualBox does have a COM API. I have no experience with it, but it may be possible to use that. One option would be to have TeamCity fire off a script to do this. I'd suggest starting with NAnt (supported natively by TeamCity) and possibly executing PowerShell if necessary.

like image 45
TrueWill Avatar answered Sep 18 '22 15:09

TrueWill