In GoogleTest documentation, here: https://google.github.io/googletest/primer.html it is written:
- Tests should be fast. With GoogleTest, you can reuse shared resources across tests and pay for the set-up/tear-down only once, without making tests depend on each other.
Specifically it is written that “pay for the set-up only once“.
In that case, wouldn’t it be possible that for example:
- Set-up created some object x.
- Test1 corrupted x.
- Then Test2 is affected by Test1?
I’m clearly missing something… what is it?
4
You can reuse shared resources across tests only if tests do not modify these shared resources.
As Marek R pointed out in here is comment. This limitation is mentioned later in GoogleTest’s documentation:
“GoogleTest creates a new test fixture object for each test in order to make tests independent and easier to debug. However, sometimes tests use resources that are expensive to set up, making the one-copy-per-test model prohibitively expensive.
If the tests don’t change the resource, there’s no harm in their sharing a single resource copy. So, in addition to per-test set-up/tear-down, GoogleTest also supports per-test-suite set-up/tear-down. “
From here: https://google.github.io/googletest/advanced.html#sharing-resources-between-tests-in-the-same-test-suite