[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling an identical setup/teardown for each test in group ?


On (06/01/16 18:07), Emil Velikov wrote:
>Hi all,
>
>Is there a way to have an identical setup/teardown which gets executed
>for each test in the group? That is without wrapping a macro around
>cmocka_unit_test_setup_teardown.
>
From API point of view current state is the clearest.
even thought you need to explicitelly write the same setup and teardown
function for each test in group.

As you mentioned you can use macro e.g.
#define new_test(test) \
    cmocka_unit_test_setup_teardown(nested_groups_test_ ## test, \
                                    nested_groups_test_setup, \
                                    nested_groups_test_teardown)

but I do not like such way.

>Afaict the current cmocka_run_group_tests allows you to do a once-off
>setup/teardown for the whole group, which is great but sadly doesn't
>fit my requirements :-( The recent prestate feature on the other hand
>seems like it does the opposite (identical test body, different
>setup/teardown) yet reading the actual implementation brings be to
>believe that's not exactly the case. Can anyone shed some light on the
>topic ?
>
>If there isn't a way to handle the above, what would be the better way
>to implement this ? A 'quick and dirty' way is to add an extra
>argument to cmocka_run_group_tests(..., bool reinit_on_each_test), but
>there should be a cleaner way.
>

cmocka_run_group_tests should not be misuused for such use case.
group_setup and group_teardown are for group and not for tests.

But there could be anouther function
cmocka_run_group_tests_with_test_setup_and_teardonwn(
    group_tests,
    group_setup, group_teardown,
    test_setup, test_teardown
)

I know the name of macro is terrible :-)

LS


Follow-Ups:
Re: Calling an identical setup/teardown for each test in group ?Emil Velikov <emil.l.velikov@xxxxxxxxx>
References:
Calling an identical setup/teardown for each test in group ?Emil Velikov <emil.l.velikov@xxxxxxxxx>