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?