Bats: Bash Automated Testing System

From Bats github page, "Bats is a TAP-compliant testing framework for Bash. It provides a simple way to verify that the UNIX programs you write behave as expected."[1]

Bats was utilized as it provides a simple way for individuals to write simple Bash closures declared using the Bats DSL to test expected behavior of OpenXT.

Getting Started

Bats is enabled/disabled using the DISTRO_FEATURE variable of the OpenEmbedded build system. This variable is declared in OpenXT's local.conf and is the best place to add the bats distro feature. Below is an example of adding bats to the current distro features,

    DISTRO_FEATURES = "alsa ext2 largefile usbhost wifi xattr pci x11 ipv4 ipv6 ${DISTRO_FEATURES_LIBC} multiarch pam bats"

When this feature is enabled there will be a "bats" command available in DOM0 along with all upstream tests installed in "/usr/lib/bats-testsuite/{dom0,ndvm,uivm}". It is possible to execute all tests by passing the directory containing the desired tests one wants to run, e.g "bats /usr/lib/bats-testsuite/dom0" will run all dom0 test scripts. To run an individual test script, pass the full path to the script, e.g. "bats /usr/lib/bats-testsuite/dom0/access_control.bats".

Writing Tests

A test script, ending in .bats, may contain one or more test. A test is effectively a bash function with the exception that if any command evaluated returns a non-zero status, then the test is deemed failing. The basic structure of a test is below,

    @test "short description show when test is ran" {
        some command
        [ -f /some/file ]

Execution of the test will result in the following output

    $ bats example.bats
     ✓ short description show when test is ran

    1 tests, 0 failures

There are more advance features available to assist in writing more complex test scenarios that can be found on Bats github page[1].

Copyright 2016 by Apertus Solutions, LLC Created by Daniel P. Smith <> This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit