Git Product home page Git Product logo

bashunit's Introduction

bashunit

bashunit is a unit testing framework for Bash scripts based on xUnit principles.

This is similar to the ShUnit and its successor shUnit2.

Usage

Functions starting with 'test' will be automatically evaluated.

1. Write test cases

testEcho() {
    assertEqual "$(echo foo)" "foo"
    assertReturn "$(echo foo)" 0
}

2. Include this script at the end of your test script

source $(dirname $0)/bashunit.bash

# eof

3. Run test suite

$ ./test_example
testEcho:4:Passed
testEcho:5:Passed
Done. 2 passed. 0 failed. 0 skipped.

The return code is equal to the amount of failed testcases.

Options can be given to the test script:

$ bash ./bashunit.bash
Usage: <testscript> [options...]

Options:
  -v, --verbose  Print expected and provided values
  -s, --summary  Only print summary omitting individual test results
  -q, --quiet    Do not print anything to standard output
  -l, --lineshow  Show failing or skipped line after line number
  -f, --failed   Print only individual failed test results
  -h, --help     Show usage screen

Dependencies

  • Bash (BASH_LINENO)
  • Shell colours

API

  • assert($1)

    $1: Expression

    Assert that a given expression evaluates to true.

  • assertEqual($1, $2)

    $1: Output

    $2: Expected

    Assert that a given output string is equal to an expected string.

  • assertNotEqual($1, $2)

    $1: Output

    $2: Expected

    Assert that a given output string is not equal to an expected string.

  • assertStartsWith($1, $2)

    $1: Output

    $2: Expected

    Assert that a given output string starts with an expected string.

  • assertReturn($1, $2)

    $1: Output

    $2: Expected

    $?: Provided

    Assert that the last command's return code is equal to an expected integer.

  • assertNotReturn($1, $2)

    $1: Output

    $2: Expected

    $?: Provided

    Assert that the last command's return code is not equal to an expected integer.

  • assertGreaterThan($1, $2)

    $1 Output

    $2 Expected

    Assert that a given integer is greater than an expected integer.

  • assertAtLeast($1, $2)

    $1 Output

    $2 Expected

    Assert that a given integer is greater than or equal to an expected integer.

  • assertLessThan($1, $2)

    $1 Output

    $2 Expected

    Assert that a given integer is less than an expected integer.

  • assertAtMost($1, $2)

    $1 Output

    $2 Expected

    Assert that a given integer is less than or equal to an expected integer.

  • skip()

    Skip the current test case.

License

bashunit is licenced under a BSD License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.