All Projects → rafritts → Bunit

rafritts / Bunit

Licence: mit
A unit testing framework for Shell scripts - namely Bash.

Programming Languages

shell
77523 projects
bash
514 projects

Labels

Projects that are alternatives of or similar to Bunit

Electricspock
Bridging Robolectric and Spock framework.
Stars: ✭ 16 (-91.26%)
Mutual labels:  unit-test
Maven Examples
List of Maven examples
Stars: ✭ 79 (-56.83%)
Mutual labels:  unit-test
React Test Demo
React test demo with Jest and Enzyme
Stars: ✭ 134 (-26.78%)
Mutual labels:  unit-test
Angular Builders
Angular build facade extensions (Jest and custom webpack configuration)
Stars: ✭ 843 (+360.66%)
Mutual labels:  unit-test
Testify
A unit testing framework written in bash for bash scripts
Stars: ✭ 45 (-75.41%)
Mutual labels:  unit-test
Kotlinrxmvparchitecture
Clean MVP Architecture with RxJava + Dagger2 + Retrofit2 + Mockito + Fresco + EasiestGenericRecyclerAdapter using Kotlin. Includes Unit Tests(Kotlin Tests)!
Stars: ✭ 94 (-48.63%)
Mutual labels:  unit-test
Gut
Godot Unit Test. Unit testing tool for Godot Game Engine.
Stars: ✭ 670 (+266.12%)
Mutual labels:  unit-test
Angular1 Webpack Starter
Component based Angular(1.x) web development with Webpack and ES6.
Stars: ✭ 148 (-19.13%)
Mutual labels:  unit-test
Tcunit
An unit testing framework for Beckhoff's TwinCAT 3
Stars: ✭ 74 (-59.56%)
Mutual labels:  unit-test
Moderncppci
This is an example of doing a Modern C++ project with CI
Stars: ✭ 109 (-40.44%)
Mutual labels:  unit-test
Nunit cshaprp cheatsheet
Example implementations of each attribute available in Nunit2 unit Testing Framework using C# .NET.
Stars: ✭ 14 (-92.35%)
Mutual labels:  unit-test
Weaponapp
一个尽量做到极致的集大成App,努力做到最好(开发阶段)——MVVM+Retrofit+RxJava+Small 插件化+单元测试+MD
Stars: ✭ 1,011 (+452.46%)
Mutual labels:  unit-test
Js Unit Testing Guide
📙 A guide to unit testing in Javascript
Stars: ✭ 1,346 (+635.52%)
Mutual labels:  unit-test
Calc
Unit Testing in JavaScript
Stars: ✭ 17 (-90.71%)
Mutual labels:  unit-test
Kotlinmvparchitecture
Clean MVP Architecture with Dagger2 + Retrofit2 + Mockito + Fresco + EasiestGenericRecyclerAdapter using Kotlin. Added Unit Tests(Kotlin Tests)!
Stars: ✭ 143 (-21.86%)
Mutual labels:  unit-test
Unit Test Demo
一步一步介绍如何给项目添加单元测试
Stars: ✭ 766 (+318.58%)
Mutual labels:  unit-test
Clarity
A declaritive test framework for Terraform
Stars: ✭ 88 (-51.91%)
Mutual labels:  unit-test
Php Conventions
Рекомендации по написанию PHP кода
Stars: ✭ 156 (-14.75%)
Mutual labels:  unit-test
Co
Art of C++. Flag, logging, unit-test, json, go-style coroutine and more.
Stars: ✭ 2,264 (+1137.16%)
Mutual labels:  unit-test
Kotlinunittesting
Kotlin Unit Testing Examples
Stars: ✭ 99 (-45.9%)
Mutual labels:  unit-test

bunit

...is a unit testing framework for Shell scripts - namely Bash.

This is a very light weight (as in one file) unit testing library for Bash scripts. It functions similarly to Java's JUnit.

You do not need to touch any of your shell scripts to run unit tests against it. That is to say, that your original source code does not need to know about bunit in order for the unit tests to work.


How to use:

Simply add the following lines underneath your shebang (#!/bin/bash) in your unit test file.

source /../bunit.shl where it points to the location of the bunit script on your local machine.

source /../ScriptToTest.sh where ScriptToTest.sh is the original script you wanted to create unit tests for.

Next, you can create any test case you like, such as:

testScriptVariableEquals5 () {
    someScriptFunctionThatSetsScriptVarToFive
    assertEquals "$ScriptVar" 5
}

You can also evaluate that certian conditions have been met, such as a process was started:

testMyProcessStarted () {
    someScriptFunctionThatStartsMyProcess
    assertTrue "pgrep myProcess.sh > /dev/null"
}

At the very bottom of your unit test suite, you need to call the function runUnitTests.

When you are ready to run your unit test suite, simply run it as you would any other script.

./MyUnitTestSuite.ut

Or you can run it verbosely using the -v or --verbose flags, which will print out all test case results, even if they pass.

./MyUnitTestSuite.ut -v
./MyUnitTestSuite.ut --verbose

!!! IMPORTANT NOTE !!!

Your unit test suite is a shell script! Therefore, if you run a dangerous command, you are going to get dangerous results! For example,

testCanDeleteHomeDirectory() {
    rm -rf ~/
    assertTrue " ! -d ~ "
}

This will absolutely delete your home directory and the assertTrue function will return a valid result, because you just blew away your home directory. Pay attention to your commands!


Functions included in bunit:

bunit includes most the assert functions found in Java's JUnit.

Specifically:

assertEquals expected actual

assertNotEquals expected actual

assertNull "actual"

assertNotNull "actual"

assertTrue "condition expression"

assertFalse "condition expression"

assertContains needle haystack

Notes:

  1. Only functions prefixed with test, i.e: test<functionName> inside of the unit test suite will be executed by runUnitTests.

  2. Null is considered to be empty string "". The assertNull requires you to enclose your argument in quotes.

  3. You must include quotes around conditional expressions. These expressions can be anything that can be evaluated in an if statement condition. Example: "-f someFile.txt"

  4. The extension .shl is an extension I perfer to give to library shell scripts. It stands for .shellLibrary.

  5. The extension .ut is an extension I prefer to give to unit test suites. It stands for .unitTest.

  6. Both of the above extensions are meaningless from a linux perspective, so you can change them to be whatever you like.

  7. If all of your unit tests pass, and you did not run the script with the verbose flag, you will see no output at all.

  8. If any of your unit tests fail, the script will exit after all tests have run, with a status code of 1.

  9. If you need to test commands that delete files or directories, it is strongly recommended to use a testSetup() function at the top of your unit test suite, and use it to create temporary files or directories that you are intentionally trying to delete. This probably goes without saying but, DO NOT TEST rm COMMANDS AGAINST PRODUCTION DATA!!!

  10. If you wish, you can also use a testTearDown() function at the bottom of your unit test suite, to clean up your tests.

  11. You can change the name of testSetup() and testTearDown(). They are not hard coded. Refer to point #1.

  12. Please see the unit tests in bunit_unit_tests and in examples for more examples.


Please remember this is a work in progress!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].