Download - Better Bash - Unit and Integration Testing
@cjcjameson3
Customer = EngineerReliability & predictable outcomes
Good bug reportsEager to make tradeoffs
@cjcjameson
How good does this need to be?The tradeoff with your Bash scripts
5
effort
time
¯\_(ツ)_/¯ ...sorry dude
@cjcjameson
cover this square with an image (540 x 480 pixels)
7
STOPWhen would anyone write a test themselves?
@cjcjameson
cover this square with an image (540 x 480 pixels)
8
STOPWhen would anyone write a test themselves?
@cjcjameson
cover this square with an image (540 x 480 pixels)
9
STOPWhen would anyone runthe tests?
@cjcjameson12 1https://en.wikipedia.org/wiki/Unit_testing
In general, unit tests...1
Find problems early Make change easy
Drive modular designAre documentationMake integration easy
@cjcjameson13
You’re writing an installer file
Be documentationMake integration easy(esp. across distros)
So your unit tests should help:
@cjcjameson14
You’re touching this code for the first and only time
Drive modular designMake change easy
So your unit tests should help:
Be documentation
@cjcjameson15
You’re treating the filesystem as a first-class object
Drive modular designFind problems early
So your unit tests should help:
@cjcjameson16
You’re writing a shared `common.bash` library
Be documentationMake integration easy
So your unit tests should help:
@cjcjameson17
You’re crafting a CLI user experience
Make change easyFind problems early
So your unit tests should help:
@cjcjameson19
Example: Concourse’s `git-resource`
https://ci.concourse.ci/pipelines/resources/jobs/git-resource
@cjcjameson23
Inside the BATS `run` commandhttps://github.com/sstephenson/bats
- Exit codes are swallowed
- `stdout` and `stderr` are swallowed
- Start by `source`ing in the file under test … so the file runs