Bats Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * bats =Script to Run all .bats Tests from a Directory= <syntaxhighlight lang='bash'> #!/usr/bin/env bash for i in $(dirname $0)/*.bats; do...")
 
Line 12: Line 12:
     bats $i
     bats $i
done
done
</syntaxhighlight>
=Loading a Library to be Tested into a .bats Test=
Assuming that the library you want to test is called blue.shlib, create a blue-library.bash file in the directory that contain the .bats tests. If the library is located at a fixed relative location to the .bats test files, use this arrangement:
<syntaxhighlight lang='bash'>
source ${BATS_TEST_DIRNAME}/[...]/blue.shlib
</syntaxhighlight>
Otherwise, you can use an absolute path, but that is more fragile.
From each .bats test that wants to test functionality from that library:
<syntaxhighlight lang='bash'>
load blue-library
</syntaxhighlight>
</syntaxhighlight>

Revision as of 16:53, 3 October 2019

Internal

Script to Run all .bats Tests from a Directory

#!/usr/bin/env bash

for i in $(dirname $0)/*.bats; do
    echo "running $(basename ${i}) tests ..."
    bats $i
done

Loading a Library to be Tested into a .bats Test

Assuming that the library you want to test is called blue.shlib, create a blue-library.bash file in the directory that contain the .bats tests. If the library is located at a fixed relative location to the .bats test files, use this arrangement:

source ${BATS_TEST_DIRNAME}/[...]/blue.shlib

Otherwise, you can use an absolute path, but that is more fragile.

From each .bats test that wants to test functionality from that library:

load blue-library