{"id":13537059,"url":"https://github.com/rafritts/bunit","last_synced_at":"2026-01-12T01:44:48.493Z","repository":{"id":155485714,"uuid":"61973497","full_name":"rafritts/bunit","owner":"rafritts","description":"A unit testing framework for Shell scripts - namely Bash.  ","archived":false,"fork":false,"pushed_at":"2022-11-03T16:09:25.000Z","size":61,"stargazers_count":197,"open_issues_count":1,"forks_count":11,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-01-02T05:03:14.379Z","etag":null,"topics":["bash","bash-scripting","shell","testing","unit-testing","unit-testing-framework"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafritts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-06-26T04:22:56.000Z","updated_at":"2024-11-01T19:16:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"a1204749-3a04-4d3a-b740-f2f5c22b47ce","html_url":"https://github.com/rafritts/bunit","commit_stats":null,"previous_names":["rafritts/bashscripttestinglibrary"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafritts%2Fbunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafritts%2Fbunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafritts%2Fbunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafritts%2Fbunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafritts","download_url":"https://codeload.github.com/rafritts/bunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246751263,"owners_count":20827860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","bash-scripting","shell","testing","unit-testing","unit-testing-framework"],"created_at":"2024-08-01T09:00:54.294Z","updated_at":"2026-01-12T01:44:48.417Z","avatar_url":"https://github.com/rafritts.png","language":"Shell","readme":"# bunit\n...is a unit testing framework for Shell scripts - namely Bash.\n\nThis is a very light weight (as in one file) unit testing library for Bash scripts.  It functions similarly to Java's JUnit.\n\nYou 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.\n\n-----\n\n### How to use:\nSimply add the following lines underneath your shebang (`#!/bin/bash`) in your unit test file.\n\n`source /../bunit.shl` where it points to the location of the bunit script on your local machine.\n\n`source /../ScriptToTest.sh`  where ScriptToTest.sh is the original script you wanted to create unit tests for.\n\nNext, you can create any test case you like, such as:\n\n```\ntestScriptVariableEquals5 () {\n    someScriptFunctionThatSetsScriptVarToFive\n    assertEquals \"$ScriptVar\" 5\n}\n```\n\nYou can also evaluate that certian conditions have been met, such as a process was started:\n\n```\ntestMyProcessStarted () {\n    someScriptFunctionThatStartsMyProcess\n    assertTrue \"pgrep myProcess.sh \u003e /dev/null\"\n}\n```\n\nAt the very bottom of your unit test suite, you need to call the function `runUnitTests`.\n\nWhen you are ready to run your unit test suite, simply run it as you would any other script.\n\n```\n./MyUnitTestSuite.ut\n```\n\nOr you can run it verbosely using the `-v` or `--verbose` flags, which will print out all test case results, even if they pass.\n\n```\n./MyUnitTestSuite.ut -v\n./MyUnitTestSuite.ut --verbose\n```\n\n-----\n### !!! IMPORTANT NOTE !!!\nYour unit test suite is a shell script! Therefore, if you run a dangerous command, you are going to get dangerous results! For example,\n\n```\ntestCanDeleteHomeDirectory() {\n    rm -rf ~/\n    assertTrue \" ! -d ~ \"\n}\n```\nThis 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!\n\n-----\n\n### Functions included in bunit:\nbunit includes most the assert functions found in Java's JUnit.\n\nSpecifically:\n\n```\nassertEquals expected actual\n\nassertNotEquals expected actual\n\nassertNull \"actual\"\n\nassertNotNull \"actual\"\n\nassertTrue \"condition expression\"\n\nassertFalse \"condition expression\"\n\nassertContains needle haystack\n```\n\n-----\n\n### Notes:\n\n1. Only functions prefixed with `test`, i.e: `test\u003cfunctionName\u003e` inside of the unit test suite will be executed by `runUnitTests`.\n\n2. Null is considered to be empty string `\"\"`. The assertNull requires you to enclose your argument in quotes.\n\n3. 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\"`\n\n4. The extension `.shl` is an extension I perfer to give to library shell scripts.  It stands for `.shellLibrary`.\n\n5. The extension `.ut` is an extension I prefer to give to unit test suites.  It stands for `.unitTest`.\n\n6. Both of the above extensions are meaningless from a linux perspective, so you can change them to be whatever you like.\n\n7. 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.\n\n8. If any of your unit tests fail, the script will exit after all tests have run, with a status code of 1.\n\n9. 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\nfiles or directories that you are intentionally trying to delete.  This probably goes without saying but, DO NOT TEST `rm` COMMANDS AGAINST PRODUCTION DATA!!!\n\n10. If you wish, you can also use a `testTearDown()` function at the bottom of your unit test suite, to clean up your tests.\n\n11. You can change the name of `testSetup()` and `testTearDown()`.  They are not hard coded.  Refer to point #1.\n\n12. Please see the unit tests in `bunit_unit_tests` and in `examples` for more examples\n","funding_links":[],"categories":["Applications","Shell Script Development"],"sub_categories":["Testing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafritts%2Fbunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafritts%2Fbunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafritts%2Fbunit/lists"}