Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Better Bash - Unit and Integration Testing

1,114 views

Published on

Presented at Velocity Santa Clara 2016, June 22

Relevant links:
https://github.com/sstephenson/bats
https://github.com/concourse/git-resource/tree/master/test
https://github.com/rbenv/ruby-build/tree/master/test

Published in: Software
  • Be the first to comment

Better Bash - Unit and Integration Testing

  1. 1. @cjcjameson1 Unit and Integration Testing C.J. Jameson Better Bash
  2. 2. @cjcjameson I work at Pivotal, I’m a Toolsmith, I tweet some 2
  3. 3. @cjcjameson3 Customer = Engineer Reliability & predictable outcomes Good bug reports Eager to make tradeoffs
  4. 4. @cjcjameson4 Tradeoffs? Customization vs. Reuse User experience vs. Exposing internals YAGNI
  5. 5. @cjcjameson How good does this need to be? The tradeoff with your Bash scripts 5 effort time ¯_(ツ)_/¯ ...sorry dude
  6. 6. @cjcjameson6 Here’s my shiny tool…?
  7. 7. @cjcjameson cover this square with an image (540 x 480 pixels) 7 STOP When would anyone write a test themselves?
  8. 8. @cjcjameson cover this square with an image (540 x 480 pixels) 8 STOP When would anyone write a test themselves?
  9. 9. @cjcjameson cover this square with an image (540 x 480 pixels) 9 STOP When would anyone run the tests?
  10. 10. @cjcjameson10 When would anyone run the tests? STOP
  11. 11. @cjcjameson11 When would anyone run the tests? P https://github.com/koalaman/shellcheck
  12. 12. @cjcjameson12 1 https://en.wikipedia.org/wiki/Unit_testing In general, unit tests...1 Find problems early Make change easy Drive modular designAre documentationMake integration easy
  13. 13. @cjcjameson13 You’re writing an installer file Be documentation Make integration easy (esp. across distros) So your unit tests should help:
  14. 14. @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
  15. 15. @cjcjameson15 You’re treating the filesystem as a first-class object Drive modular designFind problems early So your unit tests should help:
  16. 16. @cjcjameson16 You’re writing a shared `common.bash` library Be documentationMake integration easy So your unit tests should help:
  17. 17. @cjcjameson17 You’re crafting a CLI user experience Make change easyFind problems early So your unit tests should help:
  18. 18. @cjcjameson18 Example: ruby-build
  19. 19. @cjcjameson19 Example: Concourse’s `git-resource` https://ci.concourse.ci/pipelines/resources/jobs/git-resource
  20. 20. @cjcjameson20 Example: “Check the executable bit”
  21. 21. @cjcjameson21 Example: “Check the executable bit”
  22. 22. @cjcjameson22 Example: “Check the executable bit” - integration
  23. 23. @cjcjameson23 Inside the BATS `run` command https://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
  24. 24. @cjcjameson24 Thanks!

×