Home

falconindy edited this page Dec 30, 2012 · 4 revisions
Clone this wiki locally

Apron is a testing and mocking framework for Bash. It provides utilities to easily allow for testing bash functions, and avoid unwanted side effects (e.g. from calling binaries which may require root access or write unnecessarily to the filesystem).

Modules

Apron is divided up into modules, though this should never be of a concern. Apron requires that the entire suite be sourced at once via the top-level apron file.

testcase

apron-testcase provides basic tools to construct and run tests.

mock

apron-mock provides a mocking framework for diverting calls to external binaries to mocked versions, provided as functions.

assert

apron-assert is a suite of assertions which can be called to test expected values against the actual results.

Getting Started

The simplest example of using apron is as follows:

#!/bin/bash

. './apron'
. '/path/to/functions/to/test'

TEST_ApronRocks() {
  call_my_awesome_function "$with" "$args"
  APRON_assert_eq "$?" 0
}

APRON_load
APRON_run_all_tests
APRON_exit

It's important to note that apron is always sourced first, and that APRON_load is called before calling any other Apron functions. ARPON_load sets up a working directory and internal variables, enables the use of mocks, and additionally, will call APRON_setup if you've defined it. APRON_run_all_tests runs all known functions beginning with "TEST_". Note that the order of definition is not preserved (and you should never need this). Finish your tests by calling APRON_exit. This reports the status of the tests that were run, disables mocking, and optionally runs the APRON_teardown, if you've defined it.