I'm testing a particular implementation of a algorithm with random input data using google test framework. I want to use the same random input data for another implementation of the same algorithm. I'm testing the two implementation using two separate test cases. Is there a way to share the random input data from one test case to another.
Look at this section "Sharing Resources Between Tests in the Same Test Case" in https://github.com/google/googletest/blob/master/docs/advanced.md#sharing-resources-between-tests-in-the-same-test-suite
Following static methods in your test fixture class :
static void SetUpTestCase()
static void TearDownTestCase()
serve for acquisition and release of shared resources, respectively.
Of course the member variables representing that shared objects must be defined as static members of your test fixture class (static methods have access only to static members). Don't forget global variable like declaration of those members (compiler throws error if you do not declare them like that).
SetUpTestCase()
is called by Google Test Framework before execution of the first test and TearDownTestCase()
after execution of the last one.
Everything I mentioned is comprehensively described in above reference. There is also example there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With