Unit testing modules

Create and run unit tests to verify that your Puppet code compiles on supported operating systems and includes all declared resources in the catalog.

PDK runs your unit tests to ensure that your code compiles correctly and works as you expect it to, but it cannot test changes to the managed system or services.

PDK can create a basic unit test file that tests whether a manifest compiles to the catalog on the operating systems specified in the module's metadata.json file. PDK creates these unit test files when you:

  • Create a new class or defined type with the pdk new class or pdk new defined_type command.
  • Convert a module with the --add-tests option, such as pdk convert --add-tests.
  • Create new unit tests for an existing class or defined type with the pdk new test --unit command.

The unit test file is located in your module's /spec/classes (for classes) or /spec/defines (for defined types) folder. In addition to testing whether your code compiles, this file also serves as a template for writing further unit tests to ensure that your code does what you expect it to do.

The pdk test unit command runs all of the tests in your module's /spec/ directory.

Test and validate your module before modifying or adding code, to verify that you are starting out with clean code. As you develop your module, continue to validate and unit test your code.

For more information about RSpec and writing unit tests, see: