/ Vagrant-Binding / Vagrant-Binding-Demos

Vagrant-Binding-Demos

admin on 2012/11/03 - 17:35 in Vagrant-Binding

I started a demo project for Vagrant-Binding. You can use the examples in this project to start your work with Vagrant-Binding. The Vagrant-Binding-Demos project is hosted at github.
Currently there is only one example showing the use of the VagrantBuilderRule with JUnit.

DbHandler UnitTest

This UnitTest checks the functionality of the DbHandler class. This class offers some simple methods for the work with a mysql database. You can connect to a existing mysql server by JDBC and create some dummy data in it. The UnitTests checks this functions. Normally a UnitTest like the given on has some problems:

  • The mySQL server must be available
  • The tables must be empty at the start of the test
  • you can not run the test parallel to other UnitTests that use the database or the same tables

For this type of UnitTests people often use a in-memory database like Derby or H2. But sometimes you have to use a specific database. With the Vagrant-Binding you can exclude all the mentioned problems. Vagrant-Bindings offers a JUnit Rule for you that works like a wrapper around your UnitTests. With the VagrantTestRule you can sync all your tests with the lifecycle of virtual machines. In the DbHandler example a VagrantTestRule is defined with the configuration of a vm that runs MySQL server on it. The vm will be created and started before every test. When the test finishes the vm will be destroyed. So you can run your tests in parallel because every one uses its own virtual machine. The vm is created on startup with a new and empty MySQL Server on it. So you will never have a problem with old data again. The vm for this test is created by a Vagrant / Puppet config that is created by Java code.

You can check out a more detailed documentation on github.

Hope you like it.

0 POST COMMENT

Send Us A Message Here

Your email address will not be published. Required fields are marked *