Chef Blogs

Chef Guide: Accelerate test-driven development with Chef Workstation and Test Kitchen

John Tonello | Posted on | Chef Infra | Chef InSpec | Chef Workstation | Test Kitchen

Whether you’re new to Chef or an old pro, Test Kitchen can be a boon to anyone looking to dive into test-driven automation practices and rapid code development. The test suite enables you to quickly test your Chef code in souped-up Docker containers, VirtualBox, Parallels, VMware machines and in the public cloud, producing real, reliable results in moments. 

Test Kitchen is one of the free tools installed with Chef Workstation, the development environment that includes Chef CLI, InSpec, Habitat Studio and Cookstyle. A few simple kitchen commands turn your Chef recipes and tests into live machines and verify your code results. There’s no need to spin up a stable of VMs or cloud instances beforehand; Test Kitchen does it all for you. 

If you’re still running ChefDK, the now-deprecated predecessor to Chef Workstation, you won’t be able to take advantage of InSpec testing. If you haven’t upgraded, it’s well worth your time. 

Our new Chef Guide – Accelerate test-driven development with Chef and Test Kitchen – explains how to get up and running, starting with the Dokken driver. It allows you to build a wide array of Linux containers from any of the 40 special Docker images designed to run and perform like full-up machines – without the overhead. CentOS, Ubuntu, Red Hat, SUSE and most other flavors of Linux can be deployed and tested in parallel. 

driver: 
 
name: dokken 
 
use_sudo: false 
 
privileged: true   

provisioner: 
 
name: dokken 

transport: 
 
name: dokken 

verifier: 
 
name: inspec 

platforms: 
 
- name: ubuntu-20.04 
   
driver: 
     
image: dokken/ubuntu-20.04 
 
- name: centos-8 
   
driver: 
     
image: dokken/centos-8 
 
- name: oraclelinux-7 
   
driver: 
     
image: dokken/oraclelinux-7 

Simple Test Kitchen commands do the hard work: 

$ kitchen list – View the status of test nodes Test Kitchen is about to create  

$ kitchen create – Creates the raw containers, VMs or cloud instances 

$ kitchen converge – Applies your Chef code to your created nodes 

$ kitchen verify – Runs Chef InSpec tests 

$ kitchen destroy – Terminate your test instances and clean up 

You can also create, converge, verify and destroy your target nodes in one step with a single command: 

$ kitchen test 

If you prefer testing in local virtual machines or the cloud, the guide also explains how to use VirtualBox and similar VM tools for your Chef target nodes and how to extend your local test environment to AWS, Azure, CloudStack, DigitalOcean. 

Regardless of the environment, the results are fast, seamless and, frankly, fun, especially if you spend a lot of time looking for and building test nodes. 

Learn more about Chef InSpec, Chef Infra and Test Kitchen by visiting chef.io today and take a look at our recent Chef Webinar on Test-Driven Development