{"id":15048945,"url":"https://github.com/havardt/eztest","last_synced_at":"2025-10-16T00:18:03.716Z","repository":{"id":144167415,"uuid":"197949265","full_name":"havardt/EzTest","owner":"havardt","description":"An easy to use unit testing framework written in, and created for, the C language.","archived":false,"fork":false,"pushed_at":"2023-01-15T15:58:12.000Z","size":216,"stargazers_count":23,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T20:44:39.225Z","etag":null,"topics":["c","c-language","c-programming","c11","ctest","test-framework","test-macros","unit-test"],"latest_commit_sha":null,"homepage":"","language":"C","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/havardt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-20T15:34:50.000Z","updated_at":"2024-05-28T19:18:01.000Z","dependencies_parsed_at":"2023-08-11T14:46:44.082Z","dependency_job_id":null,"html_url":"https://github.com/havardt/EzTest","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/havardt/EzTest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havardt%2FEzTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havardt%2FEzTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havardt%2FEzTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havardt%2FEzTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/havardt","download_url":"https://codeload.github.com/havardt/EzTest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havardt%2FEzTest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278322146,"owners_count":25967874,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c","c-language","c-programming","c11","ctest","test-framework","test-macros","unit-test"],"created_at":"2024-09-24T21:17:17.310Z","updated_at":"2025-10-04T13:55:54.917Z","avatar_url":"https://github.com/havardt.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eEzTest\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Release](https://img.shields.io/github/v/release/havardt/eztest?label=Release)](https://github.com/havardt/EzTest/releases)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)    \n\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\u003ci\u003eAn easy to use unit testing framework written in, and created for, the C language.\u003c/i\u003e\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\".github/assets/example_output.png\"/\u003e\n\u003c/div\u003e\n\n\n\n## Table of contents\n* [Introduction](#introduction)\n* [Getting started](#getting-started)\n* [Asserts](#asserts)\n* [Runner](#runner)\n* [How to contribute](#contribute)\n* [License info](#license)\n\n## Introduction \n\n\n###### A simple test\n\n```C\nTEST(Math, AddingTwoOnTwoShouldEqualFour)\n{\n    const int expected = 4;\n    const int actual = math_add(2, 2);\n    \n    ASSERT_ARE_EQUAL(expected, actual); // or ASSERT_EQ(expected, actual); using the shorthand.\n}\n```\nThe [asserts](#asserts) are created using the power of the C11 macro ```_Generic```. As seen in the above example, this means that the user doesn't have to provide any prefix or suffix to represent the data type. \n\n###### A full test (Setup and Teardown)\nEzTest also provides the option of setup and teardown functions. The setup function is a function that runs before every test within a test suite. The teardown function has similar behaviour, but runs after the test. A test utilizing setup and teardown functions is defined by using the ```TEST_FULL(suite, name)``` macro. A setup and teardown function *must* also be defined for the test suite when using the full test macro. This is done with the ```SETUP(suite)``` and ```TEARDOWN(suite)``` macros.\n\n```C\n\nSETUP(Math)\n{\n    // Code to run before every test in the Math suite.\n}\n\nTEST_FULL(Math, AddingTwoOnTwoShouldEqualFour)\n{\n    // Test code placed here.\n}\n\nTEARDOWN(Math)\n{\n    // This code runs after every test in the Math suite.\n}\n\n```\n\nSee the next section for information on how to get started with EzTest.\n\n## Getting started\nEzTest was created to make unit testing quick and easy in C. The fastest way to get started with EzTest is by using the [template](https://github.com/havardt/EzTest-Template). The template provides a default project layout for C projects using EzTest. After getting the template or creating your own project structure, you are ready to start.\n\n#### 1. Write tests using the test macros    \nBefore having access to the test macros you need to include the eztest header file: ```#include \"eztest.h\"```.\nThere are two macros for creating tests: ```TEST(suite, test)``` and ```TEST_FULL(suite, test)```.\nThe first is for simple unit tests while the second is for tests with a setup and teardown function. Both of these macros take the same arguments.\n\n###### Argument 1: Suite\nThis is the name of the test suite that the test will be associated with. The name must follow the rules for variable names in C and must be unique through out your tests. The suite name can be used to group multiple tests providing a better overview for the tester.\n\n###### Argument 2: Test\nThis is the name of the test. The name must follow the rules for variable names in C and must be unique within the test suite.\n\nExample usage of both ```TEST(suite, test)``` and ```TEST_FULL(suite, test)``` can be found in the [usage section](#usage).     \n\n\n#### 2. Build/ Compile\n\n###### Option I: CMake/Template\nThe perhaps simplest way to build your tests is to use CMake. If you are using CMake and/or the template, then follow the build instructions given [here](https://github.com/havardt/EzTest-Template#hammer_and_wrench-build).\n\n###### Option II: Manual build\nTo build the EzTest runner, compile using a C11 compatible C compiler by providing the ```runner.c``` source file along with your test files.       \nExample compile: ```$ gcc -o ezrunner runner.c \u003ctest-files\u003e```     \n\n\n#### 3. Run\nRun the executable to run your tests. The test runner can take multiple optional arguments to customize your test experience. Learn more about the test runner [here](#runner).\n\n## Asserts\n\n| Macro | Shorthand | Description | Details |\n| --- | --- | --- | --- |\n| ``` ASSERT_IS_NULL ``` | | Tests whether the provided pointer is null. | [Documentation](doc/asserts.md#Assert-NULL) |\n| ``` ASSERT_IS_NOT_NULL ``` | | Tests whether the provided pointer is non-null. | [Documentation](doc/asserts.md#Assert-not-NULL) |\n| ``` ASSERT_IS_TRUE ``` | | Tests whether the condition is true. | [Documentation](doc/asserts.md#Assert-true) |\n| ``` ASSERT_IS_FALSE ``` | | Tests whether the condition is false. | [Documentation](doc/asserts.md#Assert-false) |\n| ``` ASSERT_ARE_SAME ``` | | Tests whether the two pointers refer to the same memory location. | [Documentation](doc/asserts.md#Assert-same) |\n| ``` ASSERT_ARE_NOT_SAME ``` | | Tests whether the two pointers refer to different memory locations. | [Documentation](doc/asserts.md#Assert-not-same) |\n| ``` ASSERT_IS_NAN ``` | | Tests whether the provided float is NaN. | [Documentation](doc/asserts.md#Assert-NaN) |\n| ``` ASSERT_ARE_EQUAL ``` | ``` ASSERT_EQ ``` | Tests whether the two values are equal. | [Documentation](doc/asserts.md#Assert-equal) |\n| ``` ASSERT_ARE_EQUAL_PRECISION ``` | ```ASSERT_EQ_PRECISION```| Tests whether two floating point numbers are equal using a user provided epsilon. | [Documentation](doc/asserts.md#Assert-equal-precision) |\n| ``` ASSERT_ARE_EQUAL_MEM ``` | ``` ASSERT_EQ_MEM ``` | Tests whether the two values are equal by comparing each byte at the given memory locations. | [Documentation](doc/asserts.md#Assert-equal-memory) |\n| ``` ASSERT_ARE_EQUAL_CMP ``` | ``` ASSERT_EQ_CMP ``` | Tests whether the two values are equal by using the passed comparator function. | [Documentation](doc/asserts.md#Assert-equal-cmp) |\n| ``` ASSERT_ARE_NOT_EQUAL ``` |``` ASSERT_NE ``` | Tests whether the two values are different. | [Documentation](doc/asserts.md#Assert-not-equal) |\n| ``` ASSERT_ARE_NOT_EQUAL_PRECISION ``` | ```ASSERT_NE_PRECISION``` | Tests whether two floating point numbers are different using a user provided epsilon. | [Documentation](doc/asserts.md#Assert-not-equal-precision) |\n| ``` ASSERT_ARE_NOT_EQUAL_MEM ``` | ```ASSERT_NE_MEM``` | Tests whether the two values are different by comparing each byte at the given memory locations. | [Documentation](doc/asserts.md#Assert-not-equal-mem) |\n| ``` ASSERT_ARE_NOT_EQUAL_CMP ``` | ``` ASSERT_NE_CMP ``` | Tests whether the two values are different by using the passed comparator function. | [Documentation](doc/asserts.md#Assert-not-equal-cmp) |\n| ``` ASSERT_GREATER ``` | ``` ASSERT_GT ``` | Tests whether the first value is greater than the second value. |\n| ``` ASSERT_GREATER_PRECISION ``` | ``` ASSERT_GT_PRECISION ``` | Tests whether the first floating point value is greater than the second floating point value using a user provided epsilon. |\n| ``` ASSERT_GREATER_MEM ``` | ```ASSERT_GT_MEM``` | Tests whether the first n bytes at the first memory location is greater than the n first bytes at the second memory location. |\n| ``` ASSERT_GREATER_CMP ``` | ``` ASSERT_GT_CMP ``` | Tests whether the first value is greater than the second value by using the passed comparator function. |\n| ``` ASSERT_GREATER_EQUAL ``` | ```ASSERT_GE``` | Tests whether the first value is greater than or equal to the second value. |\n| ``` ASSERT_GREATER_EQUAL_PRECISION ``` | ```ASSERT_GE_PRECISION``` | Tests whether the first floating point value is greater than or equal to the second floating point value using a user provided epsilon. |\n| ``` ASSERT_GREATER_EQUAL_MEM ``` | ```ASSERT_GE_MEM``` | Tests whether the first n bytes at the first memory location is greater than or equal to the n first bytes at the second memory location. |\n| ``` ASSERT_GREATER_EQUAL_CMP ``` | ``` ASSERT_GE_CMP ``` | Tests whether the first value is greater than or equal to the second value by using the passed comparator function. |\n| ``` ASSERT_LESS ``` | ``` ASSERT_LT ``` | Tests whether the first value is lesser than the second value. |\n| ``` ASSERT_LESS_PRECISION ``` | ``` ASSERT_LT_PRECISION ``` | Tests whether the first floating point value is lesser than the second floating point value using a user provided epsilon. |\n| ``` ASSERT_LESS_MEM ``` | ```ASSERT_LT_MEM``` | Tests whether the first n bytes at the first memory location is lesser than the n first bytes at the second memory location. |\n| ``` ASSERT_LESS_CMP ``` | ``` ASSERT_LT_CMP ``` | Tests whether the first value is lesser than the second value by using the passed comparator function. |\n| ``` ASSERT_LESS_EQUAL ``` | ``` ASSERT_LE ``` | Tests whether the first value is lesser than or equal to the second value. |\n| ``` ASSERT_LESS_EQUAL_PRECISION ``` | ``` ASSERT_LE_PRECISION ``` | Tests whether the first floating point value is lesser than or equal to the second floating point value using a user provided epsilon. |\n| ``` ASSERT_LESS_EQUAL_MEM ``` | ```ASSERT_LE_MEM``` | Tests whether the first n bytes at the first memory location is lesser than or equal to the n first bytes at the second memory location. |\n| ``` ASSERT_LESS_EQUAL_CMP ``` | ``` ASSERT_LE_CMP ``` | Tests whether the first value is lesser than or equal to the second value by using the passed comparator function. |\n\n## Runner\nThe runner is the program that executes the tests.\n\n#### Exit code\nThe exit code is EXIT_SUCCESS (0) if all tests passed and EXIT_FAILURE (non-zero) if one or more tests failed.\n\n#### Options\n| Short | Long\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | Description |    \n| --- | --- | --- |\n| -v | --version | Prints the version number. |       \n| -h | --help | Prints help/ usage information. |           \n| -c | --no-color | Don't use any color when printing. |  \n| -t | --timer | Display execution time for each test. |\n| -q | --quiet | No output. |\n| -s | --skip | Skips all tests in the passed list of test suits. The argument for this option should be a comma separated list of case-sensitive test suit names that you want to skip. |\n| -f | --SIGSEGV | Segmentation fault is handled like other test failures. |\n\n\n## Contribute\nWe welcome all contributions, please see the [contribution guidelines](.github/CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the MIT License - see [LICENSE.md](LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhavardt%2Feztest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhavardt%2Feztest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhavardt%2Feztest/lists"}