[asterisk-dev] Unit Test Framework Now Available!

David Vossel dvossel at digium.com
Tue Dec 22 13:20:51 CST 2009

I'm pleased to announce the introduction of the Unit Test Framework within Asterisk!

The Unit Test Framework introduces a new set of tools for creating and executing tests within a central test manager.  In the past, writing tests to verify our code has been somewhat inconvenient.  This has lead only a handful of tests actually being created.  Through the use of the new set of tools introduced by this framework, tests can now be defined immediately next to the code they verify and executed through a simple set of CLI commands.

Our hopes are that by introducing this framework, test verification will be implemented along side all new development efforts.  This will not only further enhance the quality of our code in general, but also facilitate the creation of more maintainable and verifiable code in the future.  In addition to new development, any efforts to write unit tests for existing code is more than welcome!

For detailed information on how to define and register unit tests please refer to the documentation included within the include/asterisk/test.h header file.  If you are interested in viewing an example, tests/test_heap.c has been converted to use this framework.

Feature Overview: 
- Define Unit Tests anywhere in the code using the AST_TEST_DEFINE macro
- Register Unit Tests to a central test manager using AST_TEST_REGISTER macro
- Unregister Unit Tests from the test manager using AST_TEST_UNREGISTER macro
- Execute test from CLI
- Generate xml and txt test result reports from CLI

New CLI Commands
-'test execute all'
-'test execute category'
-'test generate results xml'
-'test generate results txt'
-'test show results all'
-'test show results failed'
-'test show results passed'
-'test show registered'

- Configure Asterisk using dev mode, './configure –enable-dev-mode'
- In 'make menuselect' under the 'Compiler Flags' option enable the 'TEST_FRAMEWORK' flag.
- Recompile Asterisk and the test CLI options will be made available.

If you have any questions please feel free to contact me via email.  I'm also available in #asterisk-dev as The_Boy_Wonder.


More information about the asterisk-dev mailing list