User Guide

  1. In a module’s root directory create a directory tests and place there a module configuration file config.yaml described in detail in section Configuration file. If you would like to use MTF without your own config.yaml. It is possible. It uses default minimal config. Then you have to set URL envvar to set test subject, otherwise it causes traceback. It is usefull for example for module what does not provide any service (no own start/stop/status/etc action defined.) or for testing with modulelint.
  1. Optionally write multiline Bash snippet tests directly in the tests/config.yaml file as described in section Multiline Bash snippet tests.
  1. Check the list of Environment variables.
  1. Write your tests, for example see sanity tests and various tests examples in /usr/share/moduleframework/examples/testing-module/. All tests methods are listed in section API Index and alphabetically in Index section.
  1. In the directory tests create a Makefile as below.

    Mind to keep the mtf-generator line only if there are multiline Bash snippet tests in the tests/config.yaml file. The mtf-generator command will convert those multiline Bash snippet tests from the tests/config.yaml file into Python tests and stores them in the tests/generated.py file, which will be processed further by avocado.

MODULE_LINT=/usr/share/moduleframework/tests/generic/*.py
TESTS=*.py
CMD=avocado run $(MODULE_LINT) $(TESTS)

#
all:
    mtf-generator
    $(CMD)
  1. In a module’s root directory create a Makefile, which contains a secton test. For example:
.PHONY: build run default

IMAGE_NAME = debugging-tools
MODULEMDURL=file://debugging-tools.yaml

all: run
default: run

build:
    docker build --tag=$(IMAGE_NAME) .

run: build
    docker run -it --name $(IMAGE_NAME) --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=$(IMAGE_NAME) -e IMAGE=$(IMAGE_NAME) -v /run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -v /:/host $(IMAGE_NAME)

test: build
    cd tests; MODULE=docker MODULEMD=$(MODULEMDURL) URL="docker=$(IMAGE_NAME)" make all
    cd tests; MODULE=nspawn MODULEMD=$(MODULEMDURL) make all
    cd tests; MODULE=openshift OPENSHIFT_IP="127.0.0.1" OPENSHIFT_USER="developer" OPENSHIFT_PASSWORD="developer" make all
  1. Prepare the environment to run tests in.
  1. Execute tests from the module root directory by running
#run tests from a module root directory
$ make test

or from the tests directory by running

#run Python tests from the tests/ directory
$ sudo MODULE=docker mtf ./*.py

or

#run Bash tests from the tests/ directory
$ sudo MODULE=docker mtf ./*.sh
  1. Clean up the environment after test execution.

Contents:

See also

API Index
API Index
webchat.freenode.net
Questions? Help? Ideas? Stop by the #fedora-modularity chat channel on freenode IRC.