Testing Bash scripts

・1 min read

When you need to test a bash script you can use bats for that. That's how it is done:

#!/usr/bin/env bats

@test "addition using bc" {
  result="$(echo 2+2 | bc)"
  [ "$result" -eq 4 ]
}

@test "addition using dc" {
  result="$(echo 2 2+p | dc)"
  [ "$result" -eq 4 ]
}

bats uses special @test syntax to define tests. Inside the test's body every line should return 0 exit code or the test will fail.

Read full article here with different tools compared: https://medium.com/wemake-services/testing-bash-applications-85512e7fe2de

DISCUSS
Classic DEV Post from Jul 27 '18

Python 2 VS Python 3

There can be only one.

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️

(There is also a pink mode)