blob: 2df33d252c24394d662bc94e52b6c0533af448b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
TESTING
===
Unit Testing
------------
For Unit Testing the [cmocka](https://cmocka.org/) is used. Unit Tests resides in `tests\unit_tests.c`.
Lets see the example of how to add the test for `libnet_build_ethernet` function.
1. In `tests\unit_tests.c` add `test_libnet_build_ethernet` function. In this function implement all neccessary logic.
```c
static void
test_libnet_build_ethernet(void **state)
{
(void)state; /* unused */
...
}
```
2. Let to the `cmocka` to run this function. Add the test to the `tests[]`
```c
int
main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_libnet_build_ethernet),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
```
3. Compile and Run. See `Running Unit Tests with CMocka` in README
|