Top Banner
@cjcjameson 1 Unit and Integration Testing C.J. Jameson Better Bash
24

Better Bash - Unit and Integration Testing

Jan 25, 2017

Download

Software

C.J. Jameson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Better Bash - Unit and Integration Testing

@cjcjameson1

Unit and Integration TestingC.J. Jameson

Better Bash

Page 2: Better Bash - Unit and Integration Testing

@cjcjameson

I work at Pivotal, I’m a Toolsmith, I tweet some

2

Page 3: Better Bash - Unit and Integration Testing

@cjcjameson3

Customer = EngineerReliability & predictable outcomes

Good bug reportsEager to make tradeoffs

Page 4: Better Bash - Unit and Integration Testing

@cjcjameson4

Tradeoffs?Customization vs. Reuse

User experience vs. Exposing internalsYAGNI

Page 5: Better Bash - Unit and Integration Testing

@cjcjameson

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

5

effort

time

¯\_(ツ)_/¯ ...sorry dude

Page 6: Better Bash - Unit and Integration Testing

@cjcjameson6

Here’s my shiny tool…?

Page 7: Better Bash - Unit and Integration Testing

@cjcjameson

cover this square with an image (540 x 480 pixels)

7

STOPWhen would anyone write a test themselves?

Page 8: Better Bash - Unit and Integration Testing

@cjcjameson

cover this square with an image (540 x 480 pixels)

8

STOPWhen would anyone write a test themselves?

Page 9: Better Bash - Unit and Integration Testing

@cjcjameson

cover this square with an image (540 x 480 pixels)

9

STOPWhen would anyone runthe tests?

Page 10: Better Bash - Unit and Integration Testing

@cjcjameson10

When would anyone run the tests?

STOP

Page 11: Better Bash - Unit and Integration Testing

@cjcjameson11

When would anyone run the tests?

STOP

https://github.com/koalaman/shellcheck

Page 12: Better Bash - Unit and Integration Testing

@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

Page 13: Better Bash - Unit and Integration Testing

@cjcjameson13

You’re writing an installer file

Be documentationMake integration easy(esp. across distros)

So your unit tests should help:

Page 14: Better Bash - Unit and Integration Testing

@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

Page 15: Better Bash - Unit and Integration Testing

@cjcjameson15

You’re treating the filesystem as a first-class object

Drive modular designFind problems early

So your unit tests should help:

Page 16: Better Bash - Unit and Integration Testing

@cjcjameson16

You’re writing a shared `common.bash` library

Be documentationMake integration easy

So your unit tests should help:

Page 17: Better Bash - Unit and Integration Testing

@cjcjameson17

You’re crafting a CLI user experience

Make change easyFind problems early

So your unit tests should help:

Page 18: Better Bash - Unit and Integration Testing

@cjcjameson18

Example: ruby-build

Page 19: Better Bash - Unit and Integration Testing

@cjcjameson19

Example: Concourse’s `git-resource`

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

Page 20: Better Bash - Unit and Integration Testing

@cjcjameson20

Example: “Check the executable bit”

Page 21: Better Bash - Unit and Integration Testing

@cjcjameson21

Example: “Check the executable bit”

Page 22: Better Bash - Unit and Integration Testing

@cjcjameson22

Example: “Check the executable bit” - integration

Page 23: Better Bash - Unit and Integration Testing

@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

Page 24: Better Bash - Unit and Integration Testing

@cjcjameson24

Thanks!