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.

Hendrik Ebbers

Hendrik Ebbers is the founder of Open Elements. He is a Java champion, a member of JSR expert groups and a JavaOne rockstar. Hendrik is a member of the Eclipse JakartaEE working group (WG) and the Eclipse Adoptium WG. In addition, Hendrik Ebbers is a member of the Board of Directors of the Eclipse Foundation.

Circle Circle

Open Source made right


Privacy Policy Cookie Policy Privacy Config Impressum