Better Bash - Unit and Integration Testing

  • Published on
    25-Jan-2017

  • View
    414

  • Download
    3

Transcript

  • @cjcjameson1

    Unit and Integration TestingC.J. Jameson

    Better Bash

  • @cjcjameson

    I work at Pivotal, Im a Toolsmith, I tweet some

    2

  • @cjcjameson3

    Customer = EngineerReliability & predictable outcomes

    Good bug reportsEager to make tradeoffs

  • @cjcjameson4

    Tradeoffs?Customization vs. Reuse

    User experience vs. Exposing internalsYAGNI

  • @cjcjameson

    How good does this need to be?The tradeoff with your Bash scripts

    5

    effort

    time

    \_()_/ ...sorry dude

  • @cjcjameson6

    Heres my shiny tool?

  • @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?

  • @cjcjameson10

    When would anyone run the tests?

    STOP

  • @cjcjameson11

    When would anyone run the tests?

    STOP

    https://github.com/koalaman/shellcheck

  • @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

    Youre writing an installer file

    Be documentationMake integration easy(esp. across distros)

    So your unit tests should help:

  • @cjcjameson14

    Youre touching this code for the first and only time

    Drive modular designMake change easy

    So your unit tests should help:

    Be documentation

  • @cjcjameson15

    Youre treating the filesystem as a first-class object

    Drive modular designFind problems early

    So your unit tests should help:

  • @cjcjameson16

    Youre writing a shared `common.bash` library

    Be documentationMake integration easy

    So your unit tests should help:

  • @cjcjameson17

    Youre crafting a CLI user experience

    Make change easyFind problems early

    So your unit tests should help:

  • @cjcjameson18

    Example: ruby-build

  • @cjcjameson19

    Example: Concourses `git-resource`

    https://ci.concourse.ci/pipelines/resources/jobs/git-resource

  • @cjcjameson20

    Example: Check the executable bit

  • @cjcjameson21

    Example: Check the executable bit

  • @cjcjameson22

    Example: Check the executable bit - integration

  • @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

  • @cjcjameson24

    Thanks!

Recommended

View more >