240 likes | 461 Views
Google C++ Testing Framework. Running Test Programs: Advanced Options. Two methods. Environment variables/ Command line flags Command –help or command /? Flag in code. Disables elapsed time –command. Default Execution Code. Default Execution Results. Flag in code - GTEST_FLAG.
E N D
Google C++ Testing Framework Running Test Programs: Advanced Options
Two methods • Environment variables/ Command line flags • Command –help or command /? • Flag in code
Priority • Command line flags>Flag in code
Other Commands-Listing Test Names • Sometimes it is necessary to list the available tests in a program before running them so that a filter may be applied if needed. • Including the flag --gtest_list_tests overrides all other flags and lists tests in the following format:
Running a Subset of the Tests • Run only a subset of the tests (e.g. for debugging or quickly verifying a change). • GTEST_FILTER environment variable • --gtest_filterflag to a filter string • Examples • gtest_demo • Has no flag, and thus runs all its tests. • gtest_demo --gtest_filter=* • Also runs everything, due to the single match-everything * value. • gtest_demo --gtest_filter=FooTest.* • Runs everything in test case FooTest. • gtest_demo --gtest_filter=*Null*:*Constructor* • Runs any test whose full name contains either "Null" or "Constructor". • gtest_demo --gtest_filter=-*DeathTest.* • Runs all non-death tests. • gtest_demo --gtest_filter=FooTest.*-FooTest.Bar • Runs everything in test case FooTest except FooTest.Bar.
Repeating Tests • Once in a while you'll run into a test whose result is hit-or-miss. Perhaps it will fail only 1% of the time, making it rather hard to reproduce the bug under a debugger. This can be a major source of frustration. • The --gtest_repeat flag allows you to repeat all (or selected) test methods in a program many times. Hopefully, a flaky test will eventually fail and give you a chance to debug.
Generating Reports • Google Test can emit a detailed XML report to a file in addition to its normal textual output. • The report contains the duration of each test, and thus can help you identify slow tests. • environment variable • GTEST_OUTPUT • Flag • --gtest_output • Example • --gtest_output=xml[:DIRECTORY_PATH\|:FILE_PATH] • xml:_path_to_output_file_ • which will create the file at the given location. • default name: test_detail.xml in current directory.
Notes • The tests attribute of a <testsuites> or <testsuite> element tells how many test functions the Google Test program or test case contains, while the failures attribute tells how many of them failed. • The time attribute expresses the duration of the test, test case, or entire test program in milliseconds. • Each <failure> element corresponds to a single failed Google Test assertion. • Some JUnit concepts don't apply to Google Test, yet we have to conform to the DTD. Therefore you'll see some dummy elements and attributes in the report. You can safely ignore these parts.