diff options
| author | Bartosz Golaszewski <bartekgola@gmail.com> | 2014-06-22 16:30:41 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-22 16:30:41 +0200 |
| commit | 3ed81cf0529145d04299c4cd48b1aaab2fe36193 (patch) | |
| tree | f8d40bf4c55c9dadba0773543048a5d69b695002 /docs | |
| parent | 5d2e409ef8224dc32fde59702e8ec90b231441ed (diff) | |
| download | busybox-w32-3ed81cf0529145d04299c4cd48b1aaab2fe36193.tar.gz busybox-w32-3ed81cf0529145d04299c4cd48b1aaab2fe36193.tar.bz2 busybox-w32-3ed81cf0529145d04299c4cd48b1aaab2fe36193.zip | |
unit-tests: implement the unit-testing framework
This set of patches adds a simple unit-testing framework to Busybox
unit-tests: add some helper macros for unit-test framework implementation
unit-tests: implement the unit-testing framework
unit-tests: add basic documentation on writing the unit test cases
unit-tests: modify the Makefile 'test' target to run unit-tests too
unit-tests: add two example test cases
unit-tests: modify the existing strrstr test code to use the unit-test framework
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/unit-tests.txt | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/docs/unit-tests.txt b/docs/unit-tests.txt new file mode 100644 index 000000000..0fb522086 --- /dev/null +++ b/docs/unit-tests.txt | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | Busybox unit test framework | ||
| 2 | =========================== | ||
| 3 | |||
| 4 | This document describes what you need to do to write test cases using the | ||
| 5 | Busybox unit test framework. | ||
| 6 | |||
| 7 | |||
| 8 | Building unit tests | ||
| 9 | ------------------- | ||
| 10 | |||
| 11 | The framework and all tests are built as a regular Busybox applet if option | ||
| 12 | CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set. | ||
| 13 | |||
| 14 | |||
| 15 | Writing test cases | ||
| 16 | ------------------ | ||
| 17 | |||
| 18 | Unit testing interface can be found in include/bbunit.h. | ||
| 19 | |||
| 20 | Tests can be placed in any .c file in Busybox tree - preferably right next to | ||
| 21 | the functions they test. Test cases should be enclosed within an #if, and | ||
| 22 | should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within | ||
| 23 | the test curly brackets. If an assertion fails the test ends immediately, ie. | ||
| 24 | the following assertions will not be reached. Any code placed after | ||
| 25 | BBUNIT_ENDTEST is executed regardless of the test result. Here's an example: | ||
| 26 | |||
| 27 | #if ENABLE_UNIT_TEST | ||
| 28 | |||
| 29 | BBUNIT_DEFINE_TEST(test_name) | ||
| 30 | { | ||
| 31 | int *i; | ||
| 32 | |||
| 33 | i = malloc(sizeof(int)); | ||
| 34 | BBUNIT_ASSERT_NOTNULL(i); | ||
| 35 | *i = 2; | ||
| 36 | BBUNIT_ASSERT_EQ((*i)*(*i), 4); | ||
| 37 | |||
| 38 | BBUNIT_ENDTEST; | ||
| 39 | |||
| 40 | free(i); | ||
| 41 | } | ||
| 42 | |||
| 43 | #endif /* ENABLE_UNIT_TEST */ | ||
| 44 | |||
| 45 | |||
| 46 | Running the unit test suite | ||
| 47 | --------------------------- | ||
| 48 | |||
| 49 | To run the tests you can either directly run 'busybox unit' or use 'make test' | ||
| 50 | to run both the unit tests (if compiled) and regular test suite. | ||
