[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling an identical setup/teardown for each test in group ?
- Subject: Re: Calling an identical setup/teardown for each test in group ?
- From: Emil Velikov <emil.l.velikov@xxxxxxxxx>
- Date: Wed, 6 Jan 2016 19:29:34 +0000
- To: cmocka@xxxxxxxxxxxxxx
Hi Lukas, On 6 January 2016 at 18:38, Lukas Slebodnik <lslebodn@xxxxxxxxxx> wrote: > 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. > That's precisely what I'm currently using and indeed, it doesn't look too nice. Esp since I've wrapped that into yet another macro :-) >>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. > Ack. > 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 :-) > Minus the small typo the name looks ok imho. I'll give it a day or two for others to chip-in before cracking on. Itching to do things properly as opposed to the macro 'hack' above. Feel free to shout your preference, if any ;-) Thanks Emil
|Calling an identical setup/teardown for each test in group ?||Emil Velikov <emil.l.velikov@xxxxxxxxx>|
|Re: Calling an identical setup/teardown for each test in group ?||Lukas Slebodnik <lslebodn@xxxxxxxxxx>|