Demonstrate how to unittest functions with bats-core
NOTE: Also check 18_bats_mock
# check version
brew info bats-core
# install it
brew install bats-core
# install vscode extension
code --install-extension jetmartin.bats
Add some supporting libraries
cd ./13_bats
# Add some proper asserts to tests
git clone https://github.com/bats-core/bats-support test/test_helper/bats-support
git clone https://github.com/bats-core/bats-assert test/test_helper/bats-assert
git clone https://github.com/bats-core/bats-file test/test_helper/bats-file
# install path
which bats
# show symlink
ls -al /usr/local/bin/bats
# show installed files
ls -la /usr/local/Cellar/bats-core/1.6.0
# cat readme
cat /usr/local/Cellar/bats-core/1.6.0/README.md
# show help
test/tests.bats --help
# Pretty printed tests
bats test/tests.bats
test/tests.bats
# JUnit test results
bats -t ./test/tests.bats --formatter junit -T
# Output in tap format (shows setup and shutdown logs)
export DEBUG_BATS=true
bats -t test/tests.bats
unset DEBUG_BATS
Filtering tests is possible using a regex
./test/tests.bats -f "add_trailing_slash - No parameter"
./test/tests.bats -f "add_trailing_slash"
./test/tests.bats -f "trim"
docker run -it bats/bats:1.6.0 --version
docker run -it -v $(pwd):/mnt --workdir /mnt bats/bats:1.6.0 test/tests.bats