You should test your scripting languages as you do the rest of your codebase. Bash scripts are notorious for being inscrutable and brittle. Too often, they’re written with one purpose in mind and end up as snowflakes on servers. But these scripts are holding your build and deployment processes together. C.J. Jameson explains how to test all the things, even your bash scripts, by making assertions about what scripts represent with integration tests and driving out modular design with unit tests. Using the BATS framework, it’s cheap to write both high- and low-level tests to drive out more modular and readable bash scripts.
BATS is a simple testing framework for bash. C.J. discusses the improvements he and his teammates made around base BATS to support both integration and unit testing, shares the basic BATS project setup, and outlines additional features, showing a bash-script refactoring that is enabled and supported by two layers of test coverage. C.J. also recommends additional tools in the bash ecosystem to keep your code robust and clean, all within a normal dev workflow experience.
C.J. Jameson is a software engineer with Pivotal Labs. He has worked internally across Pivotal’s Cloud Foundry and big data platforms.
©2016, O'Reilly Media, Inc. • (800) 889-8969 or (707) 827-7019 • Monday-Friday 7:30am-5pm PT • All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners. • email@example.com