Test-Playground – Kitchen DSC for PowerShell

As a precursor to this post I want to thank Matt Wrock from Stephen Murawski Chef for all their hard work with Test-Kitchen and Kitchen-DSC.

Testing DSC Modules and Resources can be cumbersome task when having to run them locally on your machine. You may end up with tons of different undesired configurations and files sprawled throughout your machine.

This is the problem I ran into which started me down the track of looking into Test-Kitchen. If you have not heard of Test-Kitchen: One of its many features is that it essentially allows you to run isolated DSC modules/resources on a virtual machine to test their functionality and associated tests. Test-Kitchen allows cross platform use and runs on top of the Chef SDK. It requires a few steps to get it setup and working but once you get it going and functioning as intended it makes testing DSC modules quite simple.

I had a few thoughts and issues that popped up when installing and configuring Test-Kitchen which prompted me to start thinking about how I would go about making a PowerShell version that encapsulates the same concept.

In a nut shell, what we want to do:

  • Write our DSC tests
  • Write our DSC module
  • Write our DSC example configuration script
  • Press a button and have output of all these displayed on the screen

One of the cool concepts about Kitchen-DSC and Test-Playground is that there is a file that lives in the root of the repository or project root which defines the layout of the environment in which you want to run your tests and resources on. In Test-Playground I have made this a simple JSON file which allows you to place in basic information about the environment.


This JSON lays out the information we’re going to need in order for Test-Playground to gather all the files required, create the Virtual Machine and copy all of the files to the Guest OS. Let’s look at the flow of how Test-Playground works.



The flow of what we’re doing here is quite simple. We’re making a new VM differential from an existing VHD/VHDX file, copying our local content to the VM and executing some code to start our configuration and tests. At any point if we have an errors during this workflow we want to simply delete the VM and any of its content and report back the results.

One of the ideas with this project was to not only test creating custom DSC modules but also to be able to supply an example.ps1 configuration script and tests without any custom modules to be tested. This idea allows Test-Playground to be used as a development step for either creating your own modules or taking existing DSC configuration scripts and pass them into a safe execution environment for generation, execution and testing.

More information on the project and how to get started can be found on the readme of the Github repository below.

The project can be found over here and I would love any feedback or pull requests to make it better!

Please give it a try with your own DSC repository. An example DSC Repository to clone and play with can be found here. An example of a Custom DSC (Class based) module can be found here.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s