How to write an integration test

See also: Integration testing

This document demonstrates how to write an integration test for juju.

First, navigate to

In this directory, create a subdirectory named after the integration test suite you want to use. Let’s call ours example_integration_test_suite.

In your test suite directory, create a file called This file typically includes a skip block, a line where you set verbosity, a block where you check dependencies, then a bootstrapping block, a test-listing block, and a tear-down block. An example is given below. Note: The various blocks are created using multiple test includes (e.g., destroy-controller).

test_examples() {
	if [ "$(skip 'test_examples')" ]; then
		echo "==> TEST SKIPPED: example tests"


	echo "==> Checking for dependencies"
	check_dependencies juju


	bootstrap "test-example" "${file}"

	# Test that need to be run are added here!

	destroy_controller "test-example"

Also in your test suite directory, create a <test name>.sh file for every integration test you want to write. For example, we’ll create one called example_integration_test, with contents as below. This file consists of a series of subtests (below, run_example1 and run_example2) and a main function (below, test_example), which is the entrypoint to your integration test and which contains some standard logic and also runs the subtests.

run_example1() {
	# Echo out to ensure nice output to the test suite.

	# The following ensures that a bootstrap juju exists
	ensure "example1" "${file}"

	# Run your checks here
	echo "Hello example 1!" | check "Hello example 1!"

	# Clean up!
	destroy_model "example1"

run_example2() {

	ensure "example2" "${file}"

	echo "Hello example 2!" | check "Hello example 2!"

	destroy_model "example2"

test_example() {
	if [ -n "$(skip 'test_example')" ]; then
		echo "==> SKIP: Asked to skip example tests"


		cd .. || exit

		run "run_example1"
		run "run_example2"

When you are done with your test file, navigate to, open the file (which is the entrypoint to your integration testing overall) and add your test suite name to the TEST_NAMES variable.

Finally, run your integration test, following the instructions at . Essentially, what you need to do is as below:

./ [<suite_name> [<test_name>]]

Last updated 1 year, 8 months ago. Help improve this document in the forum.