Better Bash - Unit and Integration Testing

  • Published on
    25-Jan-2017

  • View
    414

  • Download
    3

Transcript

@cjcjameson1Unit and Integration TestingC.J. JamesonBetter Bash@cjcjamesonI work at Pivotal, Im a Toolsmith, I tweet some2@cjcjameson3Customer = EngineerReliability & predictable outcomesGood bug reportsEager to make tradeoffs@cjcjameson4Tradeoffs?Customization vs. ReuseUser experience vs. Exposing internalsYAGNI @cjcjamesonHow good does this need to be?The tradeoff with your Bash scripts5efforttime\_()_/ ...sorry dude@cjcjameson6Heres my shiny tool?@cjcjamesoncover this square with an image (540 x 480 pixels)7STOPWhen would anyone write a test themselves?@cjcjamesoncover this square with an image (540 x 480 pixels)8STOPWhen would anyone write a test themselves?@cjcjamesoncover this square with an image (540 x 480 pixels)9STOPWhen would anyone runthe tests?@cjcjameson10When would anyone run the tests?STOP@cjcjameson11When would anyone run the tests?STOPhttps://github.com/koalaman/shellcheck@cjcjameson12 1https://en.wikipedia.org/wiki/Unit_testingIn general, unit tests...1Find problems early Make change easyDrive modular designAre documentationMake integration easy@cjcjameson13Youre writing an installer fileBe documentationMake integration easy(esp. across distros)So your unit tests should help:@cjcjameson14Youre touching this code for the first and only timeDrive modular designMake change easySo your unit tests should help:Be documentation@cjcjameson15Youre treating the filesystem as a first-class objectDrive modular designFind problems earlySo your unit tests should help:@cjcjameson16Youre writing a shared `common.bash` libraryBe documentationMake integration easySo your unit tests should help:@cjcjameson17Youre crafting a CLI user experienceMake change easyFind problems earlySo your unit tests should help:@cjcjameson18Example: ruby-build@cjcjameson19Example: Concourses `git-resource`https://ci.concourse.ci/pipelines/resources/jobs/git-resource@cjcjameson20Example: Check the executable bit@cjcjameson21Example: Check the executable bit@cjcjameson22Example: Check the executable bit - integration@cjcjameson23Inside 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@cjcjameson24Thanks!

Recommended

View more >