Each defined test has three arguments avaliable to it's test code.
struct | ast_test_info *info | |
enum | ast_test_command cmd | |
struct | ast_test *test |
Below is an example of how to define and write a test function.
AST_TEST_DEFINE(sample_test_cb) \\The name of the callback function { \\The the function's body switch (cmd) { case TEST_INIT: info->name = "sample_test"; info->category = "main/test/"; info->summary = "sample test for example purpose"; info->description = "This demonstrates how to initialize a test function"; return AST_TEST_NOT_RUN; case TEST_EXECUTE: break; } \test code . . . if (fail) { \\ the following is just some example logic ast_test_status_update(test, "an error occured because..."); res = AST_RESULT_FAIL; } else { res = AST_RESULT_PASS } return res; \\ result must be of type enum ast_test_result_state }
Details of the test execution, especially failure details, should be provided by using the ast_test_status_update() function.
AST_TEST_REGISTER uses the callback function to retrieve all the information pertaining to a test, so the callback function is the only argument required for registering a test.
AST_TEST_REGISTER(sample_test_cb); \ Test callback function defined by AST_TEST_DEFINE
Tests are unregestered by using the AST_TEST_UNREGISTER macro.
AST_TEST_UNREGISTER(sample_test_cb); \ Remove a registered test by callback function
CLI Examples:
'test show registered all' will show every registered test. 'test execute all' will execute every registered test. 'test show results all' will show detailed results for ever executed test 'test generate results xml' will generate a test report in xml format 'test generate results txt' will generate a test report in txt format