There are two ways to skip tests with BATS:
- Marking a test as skipped in the code
- Filtering test when running
bats
Which solutions works best for you will depend on the context of your question.
skip in the code
Quoting the "skip: Easily skip tests" section of the manual:
Tests can be skipped by using the skip command at the point in a test you wish to skip.
...
Optionally, you may include a reason for skipping:
...
Or you can skip conditionally
To give you an example of all 3 of these:
@test "test2-protocol" {
skip # Just skip the test
skip "Some reason to skip this test" # Skip with a reason
if [ foo != bar ]; then
skip "foo isn't bar" # Skip under specific circumstances
fi
}
This last option, using a condition, would also allow you to skip the test when a certain environmental variable is (or isn't) set, giving you more fine-grained control.
For instance, if the test code look like this:
@test "test2-protocol" {
if [ "${SKIP_TEST}" = 'test2-protocol' ]; then
skip "Skipping test2-protocol"
fi
}
and bats is called like this:
SKIP_TEST='test2-protocol' bats -T --gather-test-outputs-in $OUTPUT/protocolTest.bat
the test will be skipped. Calling bats without setting SKIP_TEST will run all test, without skipping anything.
--filter on run
Quoting the the "Usage" section of the manual:
-f, --filter <regex> Only run tests that match the regular expression
As the filter needs a match, we need to negate the test you want to exclude.
Given the example, something like this should work:
bats -T --gather-test-outputs-in $OUTPUT/protocolTest.bat --filter 'test[^2]-protocol'
More information about negating regexes can be found on StackOverflow