Quickstart
bashunit is a dedicated testing tool crafted specifically for Bash scripts. It empowers you with tests on your Bash codebase, ensuring that your scripts operate reliably and as intended.
With an intuitive API and documentation, it streamlines the process for developers to implement and manage tests. This is beneficial regardless of the project's size or intricacy in Bash.
Thanks to bashunit, verifying and validating your Bash code has never been so easy.
Installation
There is a tool that will generate an executable with the whole library in a single file:
curl -s https://bashunit.typeddevs.com/install.sh | bash# IMPORTANT: You need WSL (Windows Subsystem for Linux) to run bashunit
#
# Step 1: Install WSL if you haven't already
# - Open PowerShell as Administrator
# - Run: wsl --install
# - Restart your computer
#
# Step 2: Open your WSL terminal and run:
curl -s https://bashunit.typeddevs.com/install.sh | bashThis will create a file inside a lib folder, such as lib/bashunit.
See more about installation.
Usage
Once bashunit is installed, you're ready to get started.
You can bootstrap a ready to use test suite with the --init option:
./lib/bashunit --init testsThis will create a tests directory containing a sample test and bootstrap file.
Alternatively, create your tests manually:
First, create a folder to place your tests:
bashmkdir testsNext, create your first test file named
example_test.shwithin this folder:bash#!/usr/bin/env bash function test_bashunit_is_working() { assert_same "bashunit is working" "bashunit is working" }Finally, run the bashunit executable:
bash./lib/bashunit ./testsIf everything works correctly, you should see an output similar to the following:
bashunit - 0.26.0 | Tests: 1 Running tests/example_test.sh ✓ Passed: Bashunit is working 16 ms Tests: 1 passed, 1 total Assertions: 1 passed, 1 total All tests passed Time taken: 90 msNow you can start testing the functionalities of your own Bash scripts.
Learning bashunit interactively
If you prefer hands-on learning, bashunit includes an interactive tutorial:
./lib/bashunit --learnThis will guide you through 10 progressive lessons covering all major features with practical exercises and immediate feedback.
Next steps
Dive deeper into the documentation:
- Common patterns - Real-world testing scenarios and best practices
- Assertions - Learn all available assertion functions
- Test doubles - Master mocks and spies for isolated testing
- Data providers - Write parameterized tests efficiently
- Snapshots - Test complex output easily
- Test files - Understand test file structure and lifecycle hooks