开发者

How to use a virtual machine with automated tests?

开发者 https://www.devze.com 2023-03-13 08:34 出处:网络
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:

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?


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.


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.


Though I don't have any experience with either, I happen to have heard of a couple applications in this space recently:

http://www.infoq.com/news/2011/05/virtual_machine_test_harness

http://www.automatedqa.com/techpapers/testcomplete/automated-testing-in-virtual-labs/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号