• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    Shell
  • License
    GNU General Publi...
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bash test framework comparison

In search of the best test framework for Bash

There are many testing frameworks for Bash. However, many of them are not actively maintained, or are used only by a small group of people.

In this comparision I've included well-established and new testing frameworks that had at least recent release and have more than 50 Stars on GitHub:

  • Bats, a mature testing library with a bit of a custom syntax for more concise tests
  • shUnit2, possibly the oldest Bash test framework around, supporting test files in pure Bash
  • bash_unit, a new and featureful test framework where test cases can be written in pure Bash
  • ShellSpec, a BDD style testing framework with its own DSL
  • shpec, a BDD style testing framework similar to RSpec, Jasmine, and mocha

Test drive

To start fiddling with any of the test projects just run the install.sh to download and extract the particular testing framework to a local directory, then execute test.sh to start the suite.

Detailed comparision

Bats shUnit2 bash_unit ShellSpec shpec
Discover and run all tests
in the project
βœ”οΈ ❌ ? ⚠ ? βœ”οΈ ? βœ”οΈ
Run subset of tests or
a specific test
βœ”οΈ ? ⚠ ? βœ”οΈ βœ”οΈ ❌ issue
Parallel test execution βœ”οΈ ❌ ❌ βœ”οΈ ❌
Skip or ignore tests βœ”οΈ ⚠ ? βœ”οΈ ? βœ”οΈ ❌ issue
Rich assertion library ⚠ ? ⚠ ? ⚠ ? βœ”οΈ ? βœ”οΈ ?
Extensible with custom assertions βœ”οΈ ? βœ”οΈ ? βœ”οΈ ? βœ”οΈ ? βœ”οΈ ?
Before / After βœ”οΈ ⚠ issue βœ”οΈ βœ”οΈ ❌ issue
BeforeAll / AfterAll ❌ issue ⚠ issue βœ”οΈ βœ”οΈ ? ❌ issue
Parameterized tests
and test data
❌ issue ❌ ❌ βœ”οΈ ❌
Mocking * βœ”οΈ ? ⚠ ? βœ”οΈ ? βœ”οΈ ? βœ”οΈ ?
Isolation between tests ** βœ”οΈ doc ❌ βœ”οΈ βœ”οΈ
Nice local report ⚠ ? βœ”οΈ βœ”οΈ βœ”οΈ βœ”οΈ
CI compatible report βœ”οΈ TAP ❌ issue βœ”οΈ TAP βœ”οΈ TAP ❌
Zero Dependency and
implemented in Bash ***
βœ”οΈ βœ”οΈ βœ”οΈ βœ”οΈ βœ”οΈ
Easy to install **** βœ”οΈ βœ”οΈ βœ”οΈ βœ”οΈ βœ”οΈ
Tests written in Bash ⚠ almost βœ”οΈ βœ”οΈ ❌ ? ❌ ?
Compatible with the
Unofficial Bash Strict Mode *****
⚠ ? βœ”οΈ ⚠ issue βœ”οΈ
Maintained ⚠ ? ⚠ ? βœ”οΈ ? βœ”οΈ ? ⚠ ?
Mature βœ”οΈ since 2011 βœ”οΈ since 2007 βœ”οΈ since 2016 ❌ since 2019 βœ”οΈ since 2013
Good documentation ⚠ ? βœ”οΈ ? βœ”οΈ ? βœ”οΈ ? βœ”οΈ ?

* Mocking:
The testing framework is compatible with the common mocking techniques.

** Isolation between tests:
Aliases, custom function definitions, Bash options and variables are not leaking from one test to another.

*** Zero Dependency and implemented in Bash:
Apart from a few common tools like coreutils and grep, you don't need anything to use the framework.
The source code of the framework is itself implemented as Bash scripts. If you are comfortable with Bash, you can read and even modify it.

**** Easy to install:
Many of the frameworks support more than one alternatives on how to set it up quickly. It's possible to install it with your favourite package manager and some of them even have an official Docker image. Personally, I try to avoid installing project dependencies globally as much as I can, so I just decided to grab a tar.gz file with the latest release from GitHub.

***** Compatible with the Unofficial Bash Strict Mode:
Sourcing a script file that use the Unofficial Bash Strict Mode should not break the test framework. Of course, custom assertions and the test code should also work with strict mode but that's up for the user. Also, the test framework shouldn't set Bash options as well to ensure that executing sourced functions work similarly to when they are not sourced.

Related posts, other comparisions

Contribution guide

If you know a testing framework that should be mentioned here or find that there's room for improvement feel free to open an issue or Pull Request. (See CONTRIBUTING.md.)

More Repositories

1

vim-disapprove-deep-indentation

ΰ² _ΰ²  Vim plugin to disapprove deeply indented code. ΰ² _ΰ² 
Vim Script
558
star
2

vim-fibo-indent

Fibonacci Indentation for Vim.
Vim Script
272
star
3

scott

Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java
Java
135
star
4

tracing-paper-sketching

Android App to copy images from the screen to physical paper.
JavaScript
15
star
5

time-admin

A simple web application for time tracking.
Scala
10
star
6

jvm-dynamic-optimizations-performance-test

Performance tests to demonstrate some of the profile-based (optimistic, speculative) optimizations performed by the JVM.
Java
7
star
7

bash-preprocessor

Bash Macros: replace snippets in a script file with their output
Shell
4
star
8

cucumber-gifreporter-experiment

Experiment to embed animated GIFs to Cucumber test reports.
Java
4
star
9

srtm-map-renderer

Java application to render SRTM data
Java
3
star
10

java-helpful-npe-demo

Java 14 Helpful NullPointerExceptions Demo
Java
2
star
11

unreal-engine-stealthgame-tutorial

A very simple single/multiplayer FPS game
C++
2
star
12

working-with-structured-data-in-java

Examples for updating, merging and comparing hierarchical data in Java, using Maps, POJOs and JsonStructures with Jackson, Apache Commons Lang, JSON-P and Guava.
Java
2
star
13

unreal-coop-shooter-game

C++
1
star
14

unreal-bullcowgame-tutorial

Word guessing terminal game in Unreal Engine 4
C++
1
star
15

AJAX-activity-indicator

This script adds onOpenGlobal and onDoneGlobal functions and numberOfOpenCalls property to XMLHttpRequest.
JavaScript
1
star
16

cucumber-attached-tests-example

Java
1
star
17

java-tutorials

Java Tutorials and Examples
Java
1
star
18

bash-jq-tutorial

Showcasing bash with jq by creating statistics based on the contents a dummy blog engine
TSQL
1
star