I'm using Bats (Bash Automated Testing System) to automate some bash unit testing. Some of these bash tests might hang forever, so I want some global timeout on my tests. I want to achieve this in my .bats
file.
I'm trying set a timeout on all of my tests in my .bats
file. I read the documentation provided by the bats wiki and found the $BATS_TEST_TIMEOUT
variable, which is exactly what I need. I set the variable in my setup_file()
as follows:
setup_file(){
BATS_TEST_TIMEOUT=5
}
@test "Dummy Loop test" {
./loop.sh
}
but my dummy infinite loop test still ran forever. Blocked by this, I tried setting other variables, like $BATS_TEST_RETRIES, and that didn't work either. I've drawn the conclusion that I must be setting them incorrectly somehow. Any ideas?
Those variables must be set in the environment of the
bats
process itself, so you can:Or:
Etc.
For example, given this test in
mytest.bats
:If I run
bats
like this:I see:
If you don't want to have to set this every time, add some sort of
run-tests.sh
script to your project that sets whatever variables you want and then callsbats
.