How to run specific test cases in GoogleTest

前端 未结 3 1967
暗喜
暗喜 2020-12-02 05:10

I am trying to write a function/method for my project, which will ask to user which all test cases are you going to run? It looks like below...,

Test_Cases_1         


        
3条回答
  •  暖寄归人
    2020-12-02 05:49

    Summarising @Rasmi Ranjan Nayak and @nogard answers and adding another option:

    On the console

    You should use the flag --gtest_filter, like

    --gtest_filter=Test_Cases1*
    

    (You can also do this in Properties|Configuration Properties|Debugging|Command Arguments)

    On the environment

    You should set the variable GTEST_FILTER like

    export GTEST_FILTER = "Test_Cases1*"
    

    On the code

    You should set a flag filter, like

    ::testing::GTEST_FLAG(filter) = "Test_Cases1*";
    

    such that your main function becomes something like

    int main(int argc, char **argv) {
        ::testing::InitGoogleTest(&argc, argv);
        ::testing::GTEST_FLAG(filter) = "Test_Cases1*";
        return RUN_ALL_TESTS();
    }
    

    See section Running a Subset of the Tests for more info on the syntax of the string you can use.

提交回复
热议问题