'How to disable or ignore a test in bash automated testing system?
I am having a set of .bat files . each file contains some tests. How can i disable one of the test ?
the following is an example
bashTester.sh
#! /bin/bash
bats -T --gather-test-outputs-in $OUTPUT/createEnvironment.bat
bats -T --gather-test-outputs-in $OUTPUT/protocolTest.bat
I want to ignore a test in the protocolTest.bat . The following are my tests in the protocolTest.bats
file.
protocolTest.bats
@test "test1-protocol" {
}
@test "test2-protocol" {
}
how can i ignore or disable the test "test2-protocol" ?
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Potherca |