Top AI Repos β open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
π§ͺ single header unit testing framework for C and C++
| Date | Stars |
|---|---|
| 2026-07-24 | 984 |
| 2026-07-25 | 984 |
| 2026-07-28 | 984 |
| 2026-07-30 | 984 |
| 2026-08-06 | 984 |
Today
β stars today
This week
β stars this week
This month
β stars this month
Momentum
15.0
growth rate 0.00%/day
# π§ͺ utest.h
[](https://github.com/sheredom/utest.h/actions)
[](https://github.com/sponsors/sheredom)
A simple one header solution to unit testing for C/C++.
## Usage
Just `#include "utest.h"` in your code!
The current supported platforms are Linux, macOS and Windows.
The current supported compilers are gcc, clang, MSVC's cl.exe, and clang-cl.exe.
It also works with tcc but with a caveat: the latest release of the tcc compiler (version 0.9.27) lacks a feature for UTEST to work. Make sure to use a tcc that is patched with the constructor attribute extension. Recent Ubuntu and Debian Linux distros ship tcc with that patch already included. If you compile tcc yourself, use the trunk version and it will work as expected.
## Command Line Options
utest.h supports some command line options:
* `--help` to output the help message
* `--filter=<filter>` will filter the test cases to run (useful for re-running one
particular offending test case).
* `--list-tests` will list testnames, one per line. Output names can be passed to `--filter`.
* `--output=<output>` will output an xunit XML file with the test results (that
Jenkins, travis-ci, and appveyor can parse for the test results).
* `--enable-mixed-units` will enable the per-test output to contain mixed units (s/ms/us/ns).
* `--random-order[=<seed>]` will randomize the order that the tests are ran in. If the optional <seed> argument is not provided, then a random starting seed is used.
## Design
UTest is a single header library to enable all the fun of unit testing in C and
C++. The library has been designed to provide an output similar to Google's
googletest framework:
```
[==========] Running 1 test cases.
[ RUN ] foo.bar
[ OK ] foo.bar (631ns)
[==========] 1 test cases ran.
[ PASSED ] 1 tests.
```
## UTEST_MAIN
In one C or C++ file, you must call the macro UTEST_MAIN:
```c
UTEST_MAIN()
```
This will call into utest.h, instantiate all the testcases and run the unit test
framework.
Alternatively, if you want to write your own main and call into utest.h, you can
instead, in one C or C++ file call:
```c
UTEST_STATE();
```
And then when you are ready to call into the utest.h framework do:
```c
int main(int argc, const char *const argv[]) {
// do your own thing
return utest_main(argc, argv);
}
```
## Define a Testcase
To define a test case to run, you can do the following;
```c
#include "utest.h"
UTEST(foo, bar) {
ASSERT_TRUE(1);
}
```
The UTEST macro takes two parameters - the first being the set that the test
case belongs to, the second being the name of the test. This allows tests to be
grouped for convenience.
## Define a Fixtured Testcase
A fixtured testcase is one in which there is a struct that is instantiated that
can be shared across multiple testcases.
```c
struct MyTestFixture {
char c;
int i;
float f;
};
UTEST_F_SETUP(MyTestFixture) {
utest_fixture->c = 'a';
utest_fixture->i = 42;
utest_fixture->f = 3.14f;
// we can even assert and expect in setup!
ASSERT_EQ(42, utest_fixture->i);
EXPECT_TRUE(true);
}
UTEST_F_TEARDOWN(MyTestFixture) {
// and also assert and expect in teardown!
ASSERT_EQ(13, utest_fixture->i);
}
UTEST_F(MyTestFixture, a) {
utest_fixture->i = 13;
// teardown will succeed because i is 13...
}
UTEST_F(MyTestFixture, b) {
utest_fixture->i = 83;
// teardown will fail because i is not 13!
}
```
Some things to note that were demonstrated above:
* We have this new implicit variable within our macros - utest_fixture. This is
a pointer to the struct you decided as your fixture (so MyTestFixture in the
above code).
* Instead of specifying a testcase set (like we do with the UTEST macro), we
instead specify the name of the fixture struct we are using.
* Every fixture has to have a `UTEST_F_SETUP` and `UTEST_F_TEARDOWN` macro -
even if they do Excerpt of 17,091 characters
Read on GitHub169
21
Facundo GalΓ‘n Β· Argentina
20
8
4
2
2
2
2
2
1
Tim Gates Β· IRESS Β· Australia
1
1
Bruce Mitchener Β· @endoli
1
1
1
1
1
1
1
Would you bet a product on this? Bounded 0β100 and slow moving.
matched fp:4bf4c76e93546746, topic:testing