分类: C/C++
2010-07-04 17:59:51
tcase_add_test() 如果一条测试条件通不过将退出循环测试,
用tcase_add_loop_test()可以解决这个问题。
|
|
85%: Checks: 7, Failures: 1, Errors: 0 unit_test/test_add.c:40:P:add:test_add:0: Passed unit_test/test_add.c:57:P:add:test_sub:0: Passed unit_test/test_add.c:51:P:add:test_loop_add:0: Passed unit_test/test_add.c:51:P:add:test_loop_add:1: Passed unit_test/test_add.c:51:P:add:test_loop_add:2: Passed unit_test/test_add.c:51:P:add:test_loop_add:3: Passed unit_test/test_add.c:51:F:add:test_loop_add:4: add函数内部计算错误 |
|
Looping tests are tests that are called with a new context for each loop iteration. This makes them ideal for table based tests. If loops are used inside ordinary tests to test multiple values, only the first error will be shown before the test exits. However, looping tests allow for all errors to be shown at once, which can help out with debugging.
Adding a normal test with tcase_add_loop_test()
instead of
tcase_add_test()
will make the test function the body of a
for
loop, with the addition of a fork before each call. The
loop variable _i
is available for use inside the test function;
for example, it could serve as an index into a table. For failures,
the iteration which caused the failure is available in error messages
and logs.
Start and end values for the loop are supplied when adding the test.
The values are used as in a normal for
loop. Below is some
pseudo-code to show the concept:
for (_i = tfun->loop_start; _i < tfun->loop_end; _i++) |
An example of looping test usage follows:
static const int primes[5] = {2,3,5,7,11}; |
Looping tests work in CK_NOFORK
mode as well, but without the
forking. This means that only the first error will be shown.