CHEF Test Kitchen: How to test CHEF recipes on your workstation

09 / Jan / 2016 by Neeraj Gupta 0 comments


It is recommended to have basic understanding of CHEF and its components. In case you want to go through the basics of CHEF click here

Use Case:

If you are already using CHEF in your environment, you often write new cookbooks and for testing those you either need to start new virtual machines or cloud instances. This activity usually takes few minutes but there is additional cost associated with launching new cloud instances. CHEF test kitchen has enabled us to reduce new cookbook/recipes testing time to minutes by provisioning VAGRANT box on our local workstation.

In this blog, I will be using mongodb-docker cookbook for demonstrating CHEF test kitchen

Install Test Kitchen, VAGRANT and VirtualBox:

    1. Chef Test Kitchen: Test Kitchen is a testing tool that can execute your CHEF recipes on one or more platforms in isolation. A driver plugin architecture is used which lets you run your recipes on various cloud providers and virtualization technologies.
$ gem install test-kitchen
    1. Virtualbox: VirtualBox is powerful Cross-platform Virtualization Software for x86-based systems. “Cross-platform” means that it can be installed on Windows, Linux, Mac OS X and Solaris x86 computers.
$ sudo apt-get install virtualbox
    1. VAGRANT: VAGRANT not only creates virtual machines, it mainly automates the work of setting up development environment.
$ sudo apt-get install vagrant

Steps to test MongoDB Replica Set Cookbook recipe with CHEF Test Kitchen:

Kitchen.yml can be created in chef-repo directory or in the recipe directory. If you initialize kitchen in recipe directory, recipe name will be automatically added to the kitchen.yml.

    1. You can create kitchen.yml file in the chef-repo directory (as shown below) or in specific cookbook directory.
$ kitchen init
    1. Add the below mentioned content to the kitchen.yml file, in this file you can configure basic details like driver name (vagrant or docker), provisioner, base OS image, memory and recipe name.
name: vagrant

name: chef_zero

- name: ubuntu-14.04
memory: 256

- name: default
- recipe[mongodb-docker::default]
    1. To create VAGRANT machine use below-mentioned command:
$ kitchen list 


$ kitchen create 


    1. To execute recipe on the VAGRANT virtual machine, use the below-mentioned command:
$ kitchen converge 


    1. To login to the VAGRANT vm, use kitchen login command as shown below:
$ kitchen login


    1. And after testing if you want to delete the setup i.e. vagrant vm, use the command mentioned-below:
$ kitchen destroy


Get in touch with our Chef devOps in case of any query.


Leave a comment -