https://github.com/urin/miniunit
Minimal unit testing framework for pure-C
https://github.com/urin/miniunit
c unit-testing
Last synced: about 1 month ago
JSON representation
Minimal unit testing framework for pure-C
- Host: GitHub
- URL: https://github.com/urin/miniunit
- Owner: urin
- License: mit
- Created: 2017-10-22T13:58:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-04-29T14:40:05.000Z (about 5 years ago)
- Last Synced: 2025-03-24T19:08:20.595Z (about 2 months ago)
- Topics: c, unit-testing
- Language: C
- Homepage:
- Size: 7.81 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# miniunit.h
miniunit.h is a unit testing framework for pure-C. It features a simple interface for defining unit tests, putting little in the way of the developer.
- header-file only
- no external dependencies (only uses standard C libraries)## Usage
Define `MINIUNIT_MAIN` before including `miniunit.h` on the main source file.
```c
#define MINIUNIT_MAIN
#include "miniunit.h"
```Just include `miniunit.h` without defining `MINIUNIT_MAIN` on other source files.
```c
#include "miniunit.h"
```### Example
```c
#define MINIUNIT_MAIN
#include "miniunit.h"int main()
{
test_case("Addition", {
expect("1 + 1 = 2", (1 + 1) == 2);
expect("1 + 1 + 1 = 3", (1 + 1 + 1) == 3);
});test_case("Subtraction", {
expect("1 - 1 = 0", (1 - 1) == 0);
expect("1 - 1 - 1 = -1", (1 - 1 - 1) == -1);
expect("example", true == false);
});return 0;
}
```outputs
```
(1) Addition
(1-1) [Passed] 1 + 1 = 2
(1-2) [Passed] 1 + 1 + 1 = 3
Elapsed time 0.001451 sec
(2) Subtraction
(2-1) [Passed] 1 - 1 = 0
(2-2) [Passed] 1 - 1 - 1 = -1
(2-3) [Failed] example (true == false) [main.c:15]
```## License
[MIT](/LICENSE)
## Author
[urin](//github.com/urin)