Better Bash - Unit and Integration Testing

  • Published on
    25-Jan-2017

  • View
    414

  • Download
    3

Embed Size (px)

Transcript

<ul><li><p>@cjcjameson1</p><p>Unit and Integration TestingC.J. Jameson</p><p>Better Bash</p></li><li><p>@cjcjameson</p><p>I work at Pivotal, Im a Toolsmith, I tweet some</p><p>2</p></li><li><p>@cjcjameson3</p><p>Customer = EngineerReliability &amp; predictable outcomes</p><p>Good bug reportsEager to make tradeoffs</p></li><li><p>@cjcjameson4</p><p>Tradeoffs?Customization vs. Reuse</p><p>User experience vs. Exposing internalsYAGNI </p></li><li><p>@cjcjameson</p><p>How good does this need to be?The tradeoff with your Bash scripts</p><p>5</p><p>effort</p><p>time</p><p>\_()_/ ...sorry dude</p></li><li><p>@cjcjameson6</p><p>Heres my shiny tool?</p></li><li><p>@cjcjameson</p><p>cover this square with an image (540 x 480 pixels)</p><p>7</p><p>STOPWhen would anyone write a test themselves?</p></li><li><p>@cjcjameson</p><p>cover this square with an image (540 x 480 pixels)</p><p>8</p><p>STOPWhen would anyone write a test themselves?</p></li><li><p>@cjcjameson</p><p>cover this square with an image (540 x 480 pixels)</p><p>9</p><p>STOPWhen would anyone runthe tests?</p></li><li><p>@cjcjameson10</p><p>When would anyone run the tests?</p><p>STOP</p></li><li><p>@cjcjameson11</p><p>When would anyone run the tests?</p><p>STOP</p><p>https://github.com/koalaman/shellcheck</p></li><li><p>@cjcjameson12 1https://en.wikipedia.org/wiki/Unit_testing</p><p>In general, unit tests...1</p><p>Find problems early Make change easy</p><p>Drive modular designAre documentationMake integration easy</p></li><li><p>@cjcjameson13</p><p>Youre writing an installer file</p><p>Be documentationMake integration easy(esp. across distros)</p><p>So your unit tests should help:</p></li><li><p>@cjcjameson14</p><p>Youre touching this code for the first and only time</p><p>Drive modular designMake change easy</p><p>So your unit tests should help:</p><p>Be documentation</p></li><li><p>@cjcjameson15</p><p>Youre treating the filesystem as a first-class object</p><p>Drive modular designFind problems early</p><p>So your unit tests should help:</p></li><li><p>@cjcjameson16</p><p>Youre writing a shared `common.bash` library</p><p>Be documentationMake integration easy</p><p>So your unit tests should help:</p></li><li><p>@cjcjameson17</p><p>Youre crafting a CLI user experience</p><p>Make change easyFind problems early</p><p>So your unit tests should help:</p></li><li><p>@cjcjameson18</p><p>Example: ruby-build</p></li><li><p>@cjcjameson19</p><p>Example: Concourses `git-resource`</p><p>https://ci.concourse.ci/pipelines/resources/jobs/git-resource</p></li><li><p>@cjcjameson20</p><p>Example: Check the executable bit</p></li><li><p>@cjcjameson21</p><p>Example: Check the executable bit</p></li><li><p>@cjcjameson22</p><p>Example: Check the executable bit - integration</p></li><li><p>@cjcjameson23</p><p>Inside the BATS `run` commandhttps://github.com/sstephenson/bats</p><p>- Exit codes are swallowed</p><p>- `stdout` and `stderr` are swallowed</p><p>- Start by `source`ing in the file under test so the file runs</p></li><li><p>@cjcjameson24</p><p>Thanks!</p></li></ul>