Where to place test/bats files

55 Views Asked by At

Where is the best place to put the bats aka test files? Do you put them in the same directory as the bash scripts you are testing? If you put them in a different directory how do you reference the bash scripts?

1

There are 1 best solutions below

0
lutzmad On

To run a script in a different folder, I add the folder to the "run" statement also.

#!/usr/bin/env bats

MY_SCRIPT='post.sh'

@test "no argument prints usage instruction" {
  run ./scripts/$MY_SCRIPT
  [ $status -eq 0 ]
  [ "${lines[0]}" == 'Usage: post.sh {start|stop|restart|status|logfile}' ]
  [ "${lines[0]%% *}" == 'Usage:' ]
}

The tested script "post.sh" is in the folder ./scripts and the used test "post.bats" is in the folder ./test, next to the folder with the scripts. I start the tests from the folder where the ./scripts and ./test folder is.