aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-06-30 21:13:06 +0100
committerRon Yorston <rmy@pobox.com>2014-06-30 21:13:06 +0100
commit099e8b6438345baae560a629d548af07a8c3125c (patch)
tree71b5600b22b0019af675e4a991394ce32c8207c5 /docs
parente19594cc6e49e78fa50a654f15cf9a04e77d054a (diff)
parent184b2669175e562d58894e22f6320cebf3316c25 (diff)
downloadbusybox-w32-099e8b6438345baae560a629d548af07a8c3125c.tar.gz
busybox-w32-099e8b6438345baae560a629d548af07a8c3125c.tar.bz2
busybox-w32-099e8b6438345baae560a629d548af07a8c3125c.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'docs')
-rw-r--r--docs/unit-tests.txt50
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 @@
1Busybox unit test framework
2===========================
3
4This document describes what you need to do to write test cases using the
5Busybox unit test framework.
6
7
8Building unit tests
9-------------------
10
11The framework and all tests are built as a regular Busybox applet if option
12CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set.
13
14
15Writing test cases
16------------------
17
18Unit testing interface can be found in include/bbunit.h.
19
20Tests can be placed in any .c file in Busybox tree - preferably right next to
21the functions they test. Test cases should be enclosed within an #if, and
22should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within
23the test curly brackets. If an assertion fails the test ends immediately, ie.
24the following assertions will not be reached. Any code placed after
25BBUNIT_ENDTEST is executed regardless of the test result. Here's an example:
26
27#if ENABLE_UNIT_TEST
28
29BBUNIT_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
46Running the unit test suite
47---------------------------
48
49To run the tests you can either directly run 'busybox unit' or use 'make test'
50to run both the unit tests (if compiled) and regular test suite.