GoogleTest: How to skip a test?

前端 未结 8 942
情歌与酒
情歌与酒 2020-12-04 08:09

Using Google Test 1.6 (Windows 7, Visual Studio C++). How can I turn off a given test? (aka how can I prevent a test from running). Is there anything I can do besides comm

8条回答
  •  暖寄归人
    2020-12-04 09:04

    You can also run a subset of tests, according to the documentation:

    Running a Subset of the Tests

    By default, a Google Test program runs all tests the user has defined. Sometimes, you want to run only a subset of the tests (e.g. for debugging or quickly verifying a change). If you set the GTEST_FILTER environment variable or the --gtest_filter flag to a filter string, Google Test will only run the tests whose full names (in the form of TestCaseName.TestName) match the filter.

    The format of a filter is a ':'-separated list of wildcard patterns (called the positive patterns) optionally followed by a '-' and another ':'-separated pattern list (called the negative patterns). A test matches the filter if and only if it matches any of the positive patterns but does not match any of the negative patterns.

    A pattern may contain '*' (matches any string) or '?' (matches any single character). For convenience, the filter '*-NegativePatterns' can be also written as '-NegativePatterns'.

    For example:

    ./foo_test Has no flag, and thus runs all its tests.
    ./foo_test --gtest_filter=* Also runs everything, due to the single match-everything * value.
    ./foo_test --gtest_filter=FooTest.* Runs everything in test case FooTest.
    ./foo_test --gtest_filter=*Null*:*Constructor* Runs any test whose full name contains either "Null" or "Constructor".
    ./foo_test --gtest_filter=-*DeathTest.* Runs all non-death tests.
    ./foo_test --gtest_filter=FooTest.*-FooTest.Bar Runs everything in test case FooTest except FooTest.Bar. 
    

    Not the prettiest solution, but it works.

提交回复
热议问题