https://github.com/mixih/cunitframework
Unit testing library implemented in pure C as an exercise
https://github.com/mixih/cunitframework
macro test-runner testing-framework
Last synced: about 2 months ago
JSON representation
Unit testing library implemented in pure C as an exercise
- Host: GitHub
- URL: https://github.com/mixih/cunitframework
- Owner: Mixih
- License: bsd-3-clause
- Created: 2020-03-02T04:59:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-09T02:04:10.000Z (about 6 years ago)
- Last Synced: 2025-12-26T20:57:47.869Z (6 months ago)
- Topics: macro, test-runner, testing-framework
- Language: C
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CUnitFramework (CUF)
A unit testing library written in pure C because I shouldn't have.
## Usage
1. Define a "uut" object
2. Declare setup and teardown functions using the SETUPFUNC and TEARDOWNFUNC
macros respectively. Note that the name you provide as the argument will be
the name of the function
3. Define testcases using the `TESTCASE()` macro.
4. Define a testsuite that hold your testcases along with setup and teardown
function
5. Register testcases to the testsuite
6. Define a test runner that handles runnign testcases and reporting
7. Register suite to test runner
8. Put three lines (minimal) into `main()`, and run.
## Example
```C
#include "test.h"
SETUPFUNC(setup) {
// common setup commands to run
}
TEARDOWNFUNC(teardown) {
// common teardown commands to run (memory deallocation, etc)
}
TESTCASE(tc1) {
// first test case. will be passed a `uut` object and a `TestSuite` object
// asserts that the two arguments are equal, and trascks the results into
// the testcase object
ASSERT_EQUAL(1,1);
}
TestRunner *create_tests() {
TestRunner *runner = testrunner_create();
Args args = {true, "ifile.temp", "ofile.temp"};
TestSuite *suite_1 = testsuite_create(&setup, &teardown);
// register the suite we defined above with a dependency on file_dep.txt
REGISTER_TESTCASE(suite_1, &tc1, "file_dep.txt", &args);
testrunner_reg_suite(runner, &suite_1, "Test Suite Name");
return runner;
}
int main() {
TestRunner *test = create_tests();
testrunner_run(test);
testrunner_destroy(test);
}
```