Skip to main content

Testing

This template provides BATS configuration and example tests for your project.

Authoring tests

This template includes a tests/bats directory with a sample Unit and Functional tests written in BATS.

The tests also include a test_helpers.bash file that provides a set of shell-command.bats is an example of Unit and Functional test for running the script with different arguments.

The CI supports running the tests with coverage reports uploaded to Codecov.

BATS

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.

This template includes a package.json used to install BATS and BATS Helpers. In addition, it provides a helper loader script _helper.bash used to configure the BATS environment and load the BATS Helpers.

Running the following command will execute all the tests:

./tests/bats/node_modules/.bin/bats tests/bats

Coverage

The template is configured to generate code coverage reports in HTML and Cobertura formats (cobertura.xml).

When tests run in CI, the reports are uploaded to Codecov.

BATS Helpers

BATS Helpers is a collection of helpers and assertions for BATS testing. It provides a set of assertions, data providers, helpers, mocking, and step runners.

The example test shell-command.bats demonstrates how to use BATS Helpers in your tests.