1BATS(1) Bash Automated Testing System BATS(1)
2
3
4
6 bats - Bash Automated Testing System
7
9 Usage: bats [OPTIONS] tests bats [-h | -v]
10
11 tests is the path to a Bats test file, or the path to a directory con‐
12 taining Bats test files (ending with ".bats")
13
15 Bats is a TAP-compliant testing framework for Bash. It provides a sim‐
16 ple way to verify that the UNIX programs you write behave as expected.
17
18 A Bats test file is a Bash script with special syntax for defining test
19 cases. Under the hood, each test case is just a function with a
20 description.
21
22 Test cases consist of standard shell commands. Bats makes use of Bash´s
23 errexit (set -e) option when running test cases. If every command in
24 the test case exits with a 0 status code (success), the test passes. In
25 this way, each line is an assertion of truth.
26
27 See bats(7) for more information on writing Bats tests.
28
30 To run your tests, invoke the bats interpreter with a path to a test
31 file. The file´s test cases are run sequentially and in isolation. If
32 all the test cases pass, bats exits with a 0 status code. If there are
33 any failures, bats exits with a 1 status code.
34
35 You can invoke the bats interpreter with multiple test file arguments,
36 or with a path to a directory containing multiple .bats files. Bats
37 will run each test file individually and aggregate the results. If any
38 test case fails, bats exits with a 1 status code.
39
41 · -c, --count: Count the number of test cases without running any
42 tests
43
44 · -f, --filter <regex>: Filter test cases by names matching the regu‐
45 lar expression
46
47 · -F, --formatter <type>: Switch between formatters: pretty
48 (default), tap (default w/o term), tap13, junit
49
50 · -h, --help: Display this help message
51
52 · -j, --jobs <jobs>: Number of parallel jobs (requires GNU parallel)
53
54 · --no-tempdir-cleanup: Preserve test output temporary directory
55
56 · --no-parallelize-across-files Serialize test file execution instead
57 of running them in parallel (requires --jobs >1)
58
59 · --no-parallelize-within-files Serialize test execution within files
60 instead of running them in parallel (requires --jobs >1)
61
62 · --report-formatter <type>: Switch between reporters (same options
63 as --formatter)
64
65 · -o, --output <dir>: Directory to write report files
66
67 · -p, --pretty: Shorthand for "--formatter pretty"
68
69 · -r, --recursive: Include tests in subdirectories
70
71 · -t, --tap: Shorthand for "--formatter tap"
72
73 · -T, --timing: Add timing information to tests
74
75 · -v, --version: Display the version number
76
77
78
80 When you run Bats from a terminal, you´ll see output as each test is
81 performed, with a check-mark next to the test´s name if it passes or an
82 "X" if it fails.
83
84
85
86 $ bats addition.bats
87 ✓ addition using bc
88 ✓ addition using dc
89
90 2 tests, 0 failures
91
92
93
94 If Bats is not connected to a terminal--in other words, if you run it
95 from a continuous integration system or redirect its output to a
96 file--the results are displayed in human-readable, machine-parsable TAP
97 format. You can force TAP output from a terminal by invoking Bats with
98 the --tap option.
99
100
101
102 $ bats --tap addition.bats
103 1..2
104 ok 1 addition using bc
105 ok 2 addition using dc
106
107
108
110 The bats interpreter exits with a value of 0 if all test cases pass, or
111 1 if one or more test cases fail.
112
114 Bats wiki: https://github.com/bats-core/bats-core/wiki/
115
116 bash(1), bats(7)
117
119 (c) 2017-2018 bats-core organization
120 (c) 2011-2016 Sam Stephenson
121
122 Bats is released under the terms of an MIT-style license.
123
124
125
126bats-core November 2020 BATS(1)