unit-tests.txt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Busybox unit test framework
  2. ===========================
  3. This document describes what you need to do to write test cases using the
  4. Busybox unit test framework.
  5. Building unit tests
  6. -------------------
  7. The framework and all tests are built as a regular Busybox applet if option
  8. CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set.
  9. Writing test cases
  10. ------------------
  11. Unit testing interface can be found in include/bbunit.h.
  12. Tests can be placed in any .c file in Busybox tree - preferably right next to
  13. the functions they test. Test cases should be enclosed within an #if, and
  14. should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within
  15. the test curly brackets. If an assertion fails the test ends immediately, ie.
  16. the following assertions will not be reached. Any code placed after
  17. BBUNIT_ENDTEST is executed regardless of the test result. Here's an example:
  18. #if ENABLE_UNIT_TEST
  19. BBUNIT_DEFINE_TEST(test_name)
  20. {
  21. int *i;
  22. i = malloc(sizeof(int));
  23. BBUNIT_ASSERT_NOTNULL(i);
  24. *i = 2;
  25. BBUNIT_ASSERT_EQ((*i)*(*i), 4);
  26. BBUNIT_ENDTEST;
  27. free(i);
  28. }
  29. #endif /* ENABLE_UNIT_TEST */
  30. Running the unit test suite
  31. ---------------------------
  32. To run the tests you can either directly run 'busybox unit' or use 'make test'
  33. to run both the unit tests (if compiled) and regular test suite.