TDD recommendations

Hi all, I’ve been trying to research best practices and sane/practical processes for moving into a TDD flow for chef cookbook development. There seems to be a few different ways to approach it, so I wanted to reach out to the gang here and see what you all are doing, how you like it, etc.

I could use all the good tips you can dish :slight_smile:

Sent from my iPhone

Hi Gregory,

I’d recommend you start by having a look at meez [0]. It will put all the basics together for you and will help you by skipping over that “where the hell should I put these files in?” initial confusion.

I would also recommend watching this video [1] by Dr Nic. That’s what made me start writing better test code for Chef. It’s a few months old, but most things are still the same. It will also introduce you to BATS, which is a handy test framework using Bash.

A few things to notice:

  • chefspec [2] is for unit testing: it won’t actually run anything. It “compiles” your recipes the same way that Chef would do, and check to see if the required resources are present given the node attributes fed into the test case;
  • Test-kitchen [3] is a test harness that helps you run integration/functional (however you want to call those) tests across multiple OSs. That said, it’s still the best tool to use even if you’re targeting a single platform. Test-kitchen uses “busser” to load plugins for the test frameworks, such as:
    ** BATS [4] (as mentioned before, uses Bash and is great for things that can be done easily through the shell);
    ** serverspec [5] is a great tool for checking for the existence of files with some content, to check for services listening on some port and much more. Great tool.
    ** Others?

I also recommend reading Test-Driven Infrastructure with Chef [6] by Stephen Nelson-Smith. It will help clarify what you should and specially what you should not be testing, and help you understand better the tools and workflows available.

[0] GitHub - paulczar/meez: rubygem to set up opinionated TDD chef cookbook
[1] http://www.youtube.com/watch?v=0sPuAb6nB2o
[2] GitHub - chefspec/chefspec: Write RSpec examples and generate coverage reports for Chef recipes!
[3] GitHub - test-kitchen/test-kitchen: Test Kitchen is an integration tool for developing and testing infrastructure code and software on isolated target platforms
[4] GitHub - sstephenson/bats: Bash Automated Testing System
[5] http://serverspec.org

--
Cassiano Leal
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Friday, February 7, 2014 at 23:23, Gregory Patmore wrote:

Hi all, I've been trying to research best practices and sane/practical processes for moving into a TDD flow for chef cookbook development. There seems to be a few different ways to approach it, so I wanted to reach out to the gang here and see what you all are doing, how you like it, etc.

I could use all the good tips you can dish :slight_smile:

Sent from my iPhone

Gregory,

I have a number of resources on TDD, including this video: http://www.youtube.com/watch?v=ZC91gZv-Uao. The content is a little outdated, but still valudable information.

Seth Vargo
Release Engineer, Chef
@sethvargo

On Feb 7, 2014, at 6:23 PM, Gregory Patmore gregorypatmore@gmail.com wrote:

Hi all, I've been trying to research best practices and sane/practical processes for moving into a TDD flow for chef cookbook development. There seems to be a few different ways to approach it, so I wanted to reach out to the gang here and see what you all are doing, how you like it, etc.

I could use all the good tips you can dish :slight_smile:

Sent from my iPhone