Using Test-Kitchen for Local Testing

Sauce AI for Test Authoring: Move from intent to execution in bit.|xBack to ResourcesBlogPosted January 24, 2017

Using Test-Kitchen for Local Testing

quote

Test Kitchenis used mainly for integration testing for yourChef Cookbooks, but it can also be used to isolate application glitch in a local environment. It is the best method to test and debug your application or infrastructure code locally using virtual technologies. Test Kitchen can converge Chef cookbooks across respective combinations of platforms (control systems). The most important panorama of this local testing model is that it & # x27; s a self-service tool anyone can use at any given clip.

Fifty-thousand ft vista of Test Kitchen

The sole use of Test Kitchen is to perform integration tests on one or more platforms in an isolated environs that has be configured from a Chef cookbook. A cookbook is use to handle the download, install, and setup of a particular service, coating, or functionality. For instance, a cookbook can be created to download and install Android SDK to build and screen an Android app locally. The tryout surroundings are delimitate in a singlekitchen.ymlfile located inside the Chef cookbook source control repository (I will stir more on the structure of this file in the next section). The trial harness supports diverse platforms, like CentOS, Ubuntu, Windows, and more. To deploy these different platforms locally, Test Kitchen will use two virtualization tools —Vagrant and VirtualBox. Test Kitchen also supports multiple Ruby examine model fromBats, Minitest, Rspec, Serverspec, and more.

How to set up a Test Kitchen environment

Before we part learning how to set up an environment employ Test Kitchen, you need to be able to reply the following two questions below:

  • Which targeted platforms and edition will your service, application or functionality need to support?

  • How are you going to manage virtual machine images?

Your organization needs to privately host the supported virtual machine images for maturation and examination.Pleasedon & # x27; t use public practical machine images to configure your organization. Why wouldn & # x27; t we desire to do that?

The first things that come to mind are the possible security risks. I recommend usingHashicorpto manage your private virtual machine ikon.

To get depart, a& quot; .kitchen.yml & quot;needs to be created at the rootage of your Chef cookbook. This file stores all the information on how and what to test. Let & # x27; s now begin walking through the structure of the kitchen.yml file.

  • The driver_nameis the gens of a driver that will be habituate to create platform instances habituate during cookbook testing. This is the default driver expend for all platforms and suites, unless a platform or suite specifies adriverto overturn the default driver for that program or suite; a driver specified for a cortege will overthrow a driver set for a platform.1

    Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

  • The provisioner_namespecifies how the chef-client will be feign during essay.chef_zero and chef_soloare the most mutual provisioners habituate for testing cookbooks.2

  • The platform-versionis the name of the platform on which Kitchen will do cookbook test. (For representative, Ubuntu-14.04 or Centos-7.2, depending on the platform.) 3

  • The suiteis a collection of test suites, with eachsuite_namegrouping defining an aspect of a cookbook to be tested. Each suite_name must determine a run-list.4

Here & # x27; s what the kitchen configuration file should look like:

---
driver:
name: vagrant # driver_name

provisioner:
name: chef_zero # provisoner_name

platforms:
- name: centos-7.2 # platform_name
- gens: ubuntu-14.04 # platform_name

suites:
- name: nonremittal
run_list:
- recipe [gd-test-helper]
- recipe [android-sdk: :default]
...

Here is a great reference papers on how to configure the kitchen.yml file.

Local Testing

Now that we have completed the review of the kitchen file structure, it ’ s time to execute a few exam kitchen commands.

For instance, we need to debug an coating bug reported on a local environment:

  • To meet a particular instance, we would run& # x27; kitchen meet centos-7.2 & # x27;.

  • When the converge has completed, we log into the converge instance by running& # x27; kitchen login & # x27;from command. Now we & # x27; re ready to execute some tryout to reproduce the coating bug describe.

Here is a list of kitchen commands we can use for test or debugging:

Conclusion

We & # x27; ve covered how to use Test Kitchen as a self-service tool for testing and debugging services, application, or functionality locally. Find the time to understand the tool inside out. It is a great puppet for team automatise their infrastructure codification, and speeds up the QA cycle. It grant us to automate the testing process, check, and debug substructure code.

1 ".kitchen.yml (driver_name) — Chef Docs.& quot; Accessed 22 Dec. 2016.
2 ".kitchen.yml (provision_name) — Chef Docs.& quot; Accessed 22 Dec. 2016.
3 ".kitchen.yml (platform_name) — Chef Docs.& quot; Accessed 22 Dec. 2016.
4 ".kitchen.yml (suites) — Chef Docs.& quot; Accessed 22 Dec. 2016.

Greg Sypolt (@ gregsypolt) is a Senior Engineer at Gannett – USA Today Network and co-founder of Quality Element. He has spent most of his career work as a developer in test— rivet on automated quiz for web browser, APIs, mobile, and more. He is rivet on the inquiry, creation, and deployment of machine-driven test scheme, testing model, tools, and uninterrupted desegregation. He ’ s passionate about # TestAutomation # TestCoverage # ContinuousIntegration # DevOps

Published:
Jan 24, 2017
Share this post
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free