docs/src/modules.md

changeset 297
ba760f2195c3
parent 295
7fc65395188e
child 298
fffe3a16a3de
equal deleted inserted replaced
296:e325716a442c 297:ba760f2195c3
436 This module provides a testing framework which allows you to execute test cases 436 This module provides a testing framework which allows you to execute test cases
437 within test suites. 437 within test suites.
438 To avoid code duplication within tests, we also provide the possibility to 438 To avoid code duplication within tests, we also provide the possibility to
439 define test subroutines. 439 define test subroutines.
440 440
441 You should declare test cases and subroutines in a header file per test unit
442 and implement them as you would implement normal functions.
443 ```C
444 /* myunit.h */
445 UCX_TEST(function_name);
446 UCX_TEST_SUBROUTINE(subroutine_name, paramlist); /* optional */
447
448
449 /* myunit.c */
450 UCX_TEST_SUBROUTINE(subroutine_name, paramlist) {
451 /* ... reusable tests with UCX_TEST_ASSERT() ... */
452 }
453
454 UCX_TEST(function_name) {
455 /* ... resource allocation and other test preparation ... */
456
457 /* mandatory marker for the start of the tests */
458 UCX_TEST_BEGIN
459
460 /* ... verifications with UCX_TEST_ASSERT() ...
461 * (and/or calls with UCX_TEST_CALL_SUBROUTINE())
462 */
463
464 /* mandatory marker for the end of the tests */
465 UCX_TEST_END
466
467 /* ... resource cleanup ...
468 * (all code after UCX_TEST_END is always executed)
469 */
470 }
471 ```
472 If you want to use the `UCX_TEST_ASSERT()` macro in a function, you are
473 *required* to use a `UCX_TEST_SUBROUTINE`.
474 Otherwise the testing framework does not know where to jump, when the assertion
475 fails.
476
477 After implementing the tests, you can easily build a test suite and execute it:
478 ```C
479 UcxTestSuite* suite = ucx_test_suite_new();
480 ucx_test_register(suite, testMyTestCase01);
481 ucx_test_register(suite, testMyTestCase02);
482 /* ... */
483 ucx_test_run(suite, stdout); /* stdout, or any other FILE stream */
484 ```
485
441 ## Utilities 486 ## Utilities
442 487
443 *Header file:* [utils.h](api/utils_8h.html) 488 *Header file:* [utils.h](api/utils_8h.html)
444 *Required modules:* [Allocator](#allocator), [String](#string) 489 *Required modules:* [Allocator](#allocator), [String](#string)
445 490

mercurial