Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am in the process of adding unit testing to a project I am working on at work and a suggestion came up that I should use VMs to populate the database with good data. This was suggested as an alternative to what I usually do which is use yaml fixture file to load the data. While I think that using a VM for the unit testing database might have some benefits, overall I do not see it as a great solution.

The first concern I have is the speed of running tests. I don't know how long it would take to bring up and tear down a new VM instance based on a snapshot but my guess is that it would be longer to the data insertions that the yaml data fixture files do. Unit tests should run as fast as possible because they should be executed at least once before any push to the version control repository and that can happen several times a day (even more when in bug fixing mode).

The next concern is having the data in a known state for all tests. Sure, the first test that is executed on the VM's database is going to know what state the database is in however once a test modifies data, that could screw up the other tests. With the yaml fixture data files, each test is guaranteed to know what state the database is in.

The last major concern is the complexity using a VM setup would probably entail (of course I could be wrong since I have never had a setup like this before). Obviously we can't just run phpunit with using VMs in the setup. First we would have to create a script that basically creates and deletes the VM. This would have to either work on all OSes or we would have to force everyone to work in a VM environment (and running a VM within a VM seems like it is really going to be even slower).

The VM suggestion was to combat the issue of managing yaml fixture data files however to me it seem like managing yaml file would be the easier of the two options.

Has anyone ever worked in an environment where developers would use VMs for the database that unit testing (or integration testing or whatever you want to call it) required and was is successful?

share|improve this question
    
What level are your unit tests intended to test? Are they really testing the entire webapp? Or are you testing individual components of your code? –  Doug T. Apr 19 '12 at 14:11
    
You can probably call them more integration tests (even though I am using PHPUnit). These are deigned to test individual components of the code (methods of helper objects, models, etc...). –  ryanzec Apr 19 '12 at 14:21

1 Answer 1

I was on a project for a large aerospace client. The application we were developing was designed to collect data from fleets using their engines worldwide. Because of the hardware requirements, we determined that it would be more cost effective to use virtualization rather than purchasing several discrete servers to host the system.

We purchased a twin set of healthy servers (4 quad core xeons 256GB ram) one for staging, the other for production. I configured the server to allow developers to self-provision their own development environments (whenever they wanted to wipe their database they just needed to click a button on the portal and it would be ready for them in a few minutes).

The unforeseen benefit of this setup was that we were able to just copy the staging VMs over to the production server and bada-bing bada-boom, we were live. That project was so successful, that it became a model for all of our future project work. And we also decided to virtualize our internal infrastructure.

So yes, it can work with the appropriate tools. We used Hyper-V and Microsoft System Center for Virtual Machine Management (SCVMM). There are similar tools available for VMWare (both first and third party) as well.

share|improve this answer
    
The setup you had does sound pretty good for a staging/production environment however we need to be able to run the unit test on local machines (our development machines). –  ryanzec Apr 19 '12 at 16:35
    
You can run local and point to a virtualized database. –  Mike Brown Apr 19 '12 at 16:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.