{"id":21285326,"url":"https://github.com/izenynn/mini-unit","last_synced_at":"2026-05-09T06:37:11.727Z","repository":{"id":163339456,"uuid":"638851126","full_name":"izenynn/mini-unit","owner":"izenynn","description":"A simple unit test framework for C and ASM in C.","archived":false,"fork":false,"pushed_at":"2024-08-16T10:55:03.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T05:15:30.122Z","etag":null,"topics":["asm","c","linux","macos","test-framework","unit-testing","unit-testing-framework","unit-testing-library","unittest","unittest-framework","unittesting","unittesting-library","unittests"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izenynn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-10T08:38:15.000Z","updated_at":"2024-08-16T10:55:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"633e3960-5123-4a4f-9769-b400f35a68db","html_url":"https://github.com/izenynn/mini-unit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izenynn%2Fmini-unit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izenynn%2Fmini-unit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izenynn%2Fmini-unit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izenynn%2Fmini-unit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izenynn","download_url":"https://codeload.github.com/izenynn/mini-unit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243746200,"owners_count":20341203,"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":["asm","c","linux","macos","test-framework","unit-testing","unit-testing-framework","unit-testing-library","unittest","unittest-framework","unittesting","unittesting-library","unittests"],"created_at":"2024-11-21T11:19:42.504Z","updated_at":"2026-05-09T06:37:06.689Z","avatar_url":"https://github.com/izenynn.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mini-unit\n\n## Contents\n\n- [Info](#info)\n- [Usage](#usage)\n- [Automatic tests execution](#automatic-tests-execution)\n\t- [With the provided Makefile](#with-the-provided-makefile)\n\t- [An example of a custom Makefile](#an-example-of-a-custom-makefile)\n\t- [Other](#other)\n\n## Info\n\nA simple unit test framework for C and ASM in C.\n\n*Written in just one small .h! :D*\n\n## Usage\n\nThis project aims to keep unit testing simple, so its pretty easy to use.\n\nFirst, create a test `.c` file, for unit testing I don't like to have the test files in a `tests/` directory, I prefer to put them next to the respective `.c` so I have both files at hand easily.\n\nUsually a name it `*_test.c`, so for the `foo.c` file I would create `foo_test.c`.\n\nFirst include the library:\n```c\n#include \"miniunit.h\"\n// ... other includes\n```\n*Note: don't forget to compile with `-I./MINI_UNIT_DIR`*\n\nThen, add a `TEST_MAIN` and make sure you call the `END()` macro at the end:\n```c\n#include \"miniunit.h\"\n\n// END() will output the result and exit with 0 if successful, or 1 if failure,\n// you can take advatage of that if you automate the execution of tests\nTEST_MAIN {\n    END();\n}\n```\n\nNow, you can add `TEST_CASE`s and `ASSERT`s inside them, and call them from `TEST_MAIN` using `RUN_TEST`:\n```c\n#include \"miniunit.h\"\n\nTEST_CASE(foo) {\n    int bar = 42;\n    ASSERT(bar == 42, \"bar is not 42!\");\n}\n\nTEST_MAIN {\n    RUN_TEST(foo);\n    END();\n}\n```\n\nOf course you can scale this all you want, you can call multiple `ASSERT`s in one `TEST_CASE`, do more `TEST_CASE`s, and since this is just C with macros, you can do whatever you want.\n\nJust renember to call the `TEST_CASE`s using `RUN_TEST`, and to call `END()` at the end.\n\n*For a complete usage example, you can check my `libasm` project [here](https://github.com/izenynn/libasm), in which I use `mini-unit` to test the functions of the library.*\n\n## Automatic tests execution\n\n### With the provided Makefile\n\nFor unit testing I don't like to have the test files in a `tests/` folder, I prefer to put them next to the respective `.c` so I have both files at hand easily.\n\nIf you also like to place your tests with the original file, you can use the provided `Makefile` for automating your tests, just clone this project inside your project directory:\n```bash\ngit clone --recurse-submodules https://github.com/izenynn/mini-unit.git\n```\n\nAnd assuming you project structure is as follows:\n```\nproject/\n├── ...\n├── include/\n├── src/\n├── Makefile\n└── mini-unit/\n    ├── Makefile\n    └── ...\n```\n\nadd this to your project Makefile:\n```makefile\n# define the necessary variables\n\n# mini-unit location :)\nTEST_DIR := mini-unit\n\n# your test files\nTEST_SRC_FILES := \\\n\t\tft_strlen_test.c\t\\\n\t\tft_strcmp_test.c\n# in my case I have them inside a `src/` directory\nTEST_SRC := $(addprefix $(SRC_DIR)/, $(TEST_SRC_FILES))\n```\n```makefile\n# create a check rule and make sure you are providing the necessary values:\n#   - `SRC`: your project src files, in my case it would be something\n#            like `src/ft_strlen.c src/ft_strcmp.c ...`\n#\n#   - `TEST_SRC`: test sources as showed above\n#\n#   - `RELATIVE_PATH`: the relative path to your project from the 'mini-unit'\n#                      directory location.\n#\n#                      this is also used to cut it off from test log output\n#                      so instead of `../src/ft_strlen_test.c` it prints the\n#                      rute relative to the project `src/ft_strlen_test.c`\n#\n#                      if you add this to your own Makefile make sure it has the\n#                      correct syntax, check the provided Makefile for details\n#\n#   - `INCLUDES`: mini-unit includes your project path with -I./$(RELATIVE_PATH)\n#                 but if you compile your project with -I./\u003csome_path\u003e,\n#                 add those paths here separated with spaces.\ncheck:\n\t$(MAKE) -C $(TEST_DIR) SRC='$(SRC)' TEST_SRC='$(TEST_SRC)' RELATIVE_PATH='..' INCLUDES='include'\n\n# update your clean rule\nclean:\n\t$(MAKE) -C $(TEST_DIR) fclean\n\t# ...\n```\n\n*To check a working `Makefile`, you can check my `libasm` project `Makefile` [here](https://github.com/izenynn/libasm).*\n\nAnd that's all, now run `make test` and have fun! :D\n\n### An example of a custom Makefile\n\nIf the provided `Makefile` is not an option for your project, you would probably want to add some `test` rule to your project `Makefile`, here is a quick example assuming your test files follow the `*_test.c` naming convention:\n\n```makefile\nCC = gcc\nCFLAGS = -Wall -Werror -Wextra\nSRC = $(wildcard src/*.c)\nTEST_SRC = $(wildcard src/*_test.c)\nOBJ = $(SRC:.c=.o)\nTEST_OBJ = $(TEST_SRC:.c=.o)\nTEST_BIN = $(patsubst src/%,tests/%,$(TEST_SRC:.c=.test))\n\nall: $(NAME)\n\n# ...\n\ncheck: $(TEST_BIN)\n\t@total=0; success=0; failure=0; \\\n\tfor test in $^; do \\\n\t\t./$$test; \\\n\t\texit_code=$$?; \\\n\t\tif [ $$exit_code -eq 0 ]; then \\\n\t\t\tsuccess=$$((success+1)); \\\n\t\telse \\\n\t\t\tfailure=$$((failure+1)); \\\n\t\tfi; \\\n\t\ttotal=$$((total+1)); \\\n\tdone; \\\n\techo \"============================================================\"; \\\n\techo \"test summary\"; \\\n\techo \"============================================================\"; \\\n\techo \"# TOTAL: $$total\"; \\\n\techo \"# PASS:  $$success\"; \\\n\techo \"# FAIL:  $$failure\"; \\\n\techo \"============================================================\";\n\n%.o: %.c\n\t$(CC) $(CFLAGS) -c $\u003c -o $@\n\ntests/%_test.test: src/%_test.o $(filter-out %_test.o, $(OBJ))\n\t@mkdir -p tests\n\t$(CC) $(CFLAGS) $^ -o $@\n\nclean:\n\trm -f $(OBJ) $(TEST_OBJ)\n\trm -rf tests\n\n.PHONY: all clean test\n.SECONDARY: $(TEST_OBJ)\n```\n\n### Other\n\nThis is a pretty simple test framework, is just some `.h` file, there are tons of ways to make it work with your project, so you can just use the `.h` and implement the automatic execution of the tests in a way that fits your project! :D\n\n##\n\n[![forthebadge](https://forthebadge.com/images/badges/made-with-c.svg)](https://forthebadge.com)\n[![forthebadge](https://forthebadge.com/images/badges/makes-people-smile.svg)](https://forthebadge.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizenynn%2Fmini-unit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizenynn%2Fmini-unit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizenynn%2Fmini-unit/lists"}