hgraca/shunit

A unit testing framework for shell scripts functions.

Maintainers

Details

gitlab.com/hgraca/shunit

Source

Issues

Installs: 11

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:shell-project

v0.2.0 2023-08-01 21:35 UTC

This package is auto-updated.

Last update: 2024-10-30 01:37:23 UTC


README

A unit test framework for shell scripts.

How to use

You can install this library in your project, using composer.

Once you have composer installed in your system, you can run composer install, which will install all dependencies and generate the autoloader in vendor/autoload.sh.

For an example, you can check the project Bash Overlay.

Creating and running test suites

Create a test by naming it with the suffix .unit_test.sh, ie my_test.unit_test.sh and put your tests in it while naming the functions with the prefix unit_test.

Ex:

Create this test file and put it in a folder ./tests:

#!/usr/bin/env bash

unit_test.it_should_test_something() {

  if [ "666" == "666" ]; then
    return $0
  fi

  echo "Some error message explaining what failed"
  return $1
}

Execute this test, and all other tests in the folder and sub-folders, by running:

./vendor/bin/shunit ./tests

Bootstrapping your tests

If you want to run some bootstrapping before running your tests, for example to set the logs level, you can do so in the file tests/bootstrap.sh.

Running this project tests

You can run this project test suite by running composer test.