GTestCase's setup/teardown functions appear pointless
Submitted by Dan Williams
Link to original bug (#603749)
Description
The docs gtestutils.c::g_test_create_case() imply that you can use the same fixture across multiple tests, but the code doesn't appear to allow that.
- Splitting up a test run into fixture setup, test function and
- fixture teardown is most usful if the same fixture is used for
- multiple tests. In this cases, g_test_create_case() will be
- called with the same fixture, but varying @test_name and
- @data_test arguments.
However, test_case_run() basically does:
- new fixture
- if (fixture_setup) fixture_setup()
- fixture_test()
- if (fixture_teardown) fixture_teardown()
there doesn't seem to be any support for using the same fixture for multiple test since it's set up and torn down for each test.
I've got a couple of tests that all use the same basic data, which I'd like to pre-generate in the setup function and free in teardown. However, it looks like I can't do that.
One way to fix this might be to add GTestSuite setup/teardown callbacks which get called before/after running that suite's cases, and any testcases owned by that suite get 'fixture' set by the suite if they don't provide fixture_size themselves?
I think what's missing here is being able to group a few cases together as "related" cases that can use the same data. The most logical place to do that at the moment seems to be the GTestSuite unless somebody wants to add GTestCaseGroup that takes the setup/teardown values instead.
See also bug #544244 which could probably make use of some of the fix for this one.