{"id":21251218,"url":"https://github.com/gvaliente/catch-mini","last_synced_at":"2025-07-15T07:33:05.515Z","repository":{"id":201436185,"uuid":"130249719","full_name":"GValiente/catch-mini","owner":"GValiente","description":"Minimal subset of Catch2 C++ test framework","archived":false,"fork":false,"pushed_at":"2018-10-02T21:32:08.000Z","size":10,"stargazers_count":24,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-10-19T20:15:12.805Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GValiente.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}},"created_at":"2018-04-19T17:26:23.000Z","updated_at":"2023-10-19T21:17:24.631Z","dependencies_parsed_at":null,"dependency_job_id":"cf554584-b7cc-445f-bbe3-83d60c57dac0","html_url":"https://github.com/GValiente/catch-mini","commit_stats":null,"previous_names":["gvaliente/catch-mini"],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GValiente%2Fcatch-mini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GValiente%2Fcatch-mini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GValiente%2Fcatch-mini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GValiente%2Fcatch-mini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GValiente","download_url":"https://codeload.github.com/GValiente/catch-mini/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225669674,"owners_count":17505363,"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":[],"created_at":"2024-11-21T03:41:05.509Z","updated_at":"2024-11-21T03:41:06.206Z","avatar_url":"https://github.com/GValiente.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# catch-mini\n\ncatch-mini is a minimal subset of [Catch2 C++ test framework](https://github.com/catchorg/Catch2), implemented in less than 300 lines of code.  \n\nIt is distributed as a single header file. To replace Catch with catch-mini you only need to replace this header file, so if you only need Catch's basic functionality (`TEST_CASE` and `REQUIRE` macros), catch-mini can be useful to you.\n\n## Why do we need yet another C++ test framework?\n\nGood question. For C++ there are quite a number of established frameworks, including (but not limited to),\n[Catch2](https://github.com/catchorg/Catch2),\n[Google Test](http://code.google.com/p/googletest/),\n[Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html),\n[CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page),\n[Cute](http://r2.ifs.hsr.ch/cute),\n[many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B).\n\nSo what does catch-mini bring to the party that differentiates it from these?\n\n* Quick and really easy to get started. Just download catch.hpp, `#include` it and you're away.\n* No external dependencies. As long as you can compile C++11 and have a C++ standard library available.\n* Write test cases as, self-registering, functions.\n* Tests are named using free-form strings - no more couching names in legal identifiers.\n* Fast build times, since it is implemented in less than 300 lines of code.\n\n## Where to put catch-mini?\n\ncatch-mini is header only. All you need to do is drop the catch.hpp file somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself!\n\nThe rest of this tutorial will assume that the catch-mini single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.\n\n## Writing tests\n\nSay you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now). \n\n```c++\nunsigned int Factorial(unsigned int number) {\n    return number \u003c= 1 ? number : Factorial(number - 1) * number;\n}\n```\n\nTo keep things simple we'll put everything in a single file (\u003ca href=\"#scaling-up\"\u003esee later for more on how to structure your test files\u003c/a\u003e).\n\n```c++\n#define CATCH_CONFIG_MAIN // This tells catch-mini to provide a main() - only do this in one cpp file\n#include \"catch.hpp\"\n\nunsigned int Factorial(unsigned int number) {\n    return number \u003c= 1 ? number : Factorial(number - 1) * number;\n}\n\nTEST_CASE(\"Factorials\") {\n    REQUIRE(Factorial(1) == 1);\n    REQUIRE(Factorial(2) == 2);\n    REQUIRE(Factorial(3) == 6);\n    REQUIRE(Factorial(10) == 3628800);\n}\n```\n\nThis will compile to a complete executable which will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: \"did it work\").\n\n\u003ca id=\"scaling-up\"\u003e\u003c/a\u003e\n## Scaling up\n\nTo keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into catch-mini even quicker and easier. As you write more real-world tests, though, this is not really the best approach.\n\nThe requirement is that the following block of code:\n\n```c++\n#define CATCH_CONFIG_MAIN\n#include \"catch.hpp\"\n```\n\nappears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include \"catch.hpp\"``` - do not repeat the ```#define```!\n\nDo not write your tests in header files!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgvaliente%2Fcatch-mini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgvaliente%2Fcatch-mini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgvaliente%2Fcatch-mini/lists"}