Search code examples
c++testinggoogletestrandom-testing

Calling several times a single test - Google Tests


I am trying to perform a little of random testing in a piece of software I am developing.
I have a fixture that is initialized with random values, therefore, each test will have different input.

Moreover, what I want is to run one of those test several times(I expect the fixture to be initialized randomly for each execution), is it possible in Google Tests? I need that to be in the code, not to use a argument or something like that.

I am looking for something like invocationCount in JUnit.


Solution

  • How about something like this, using an unused parameter and Range()

    class Fixture : public ::testing::TestWithParam<int> {
        //Random initialisation
    };
    
    TEST_P(Fixture, Test1){}
    
    INSTANTIATE_TEST_CASE_P(Instantiation, Fixture, ::testing::Range(1, 11));
    

    Test1 wil be called 10 times (the range end, 11, isn't included), with a new fixture created each time.