Google C++ Testing Framework

18
Google C++ Testing Framework Running Test Programs: Advanced Options

description

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. - PowerPoint PPT Presentation

Transcript of Google C++ Testing Framework

Page 1: Google C++ Testing Framework

Google C++ Testing Framework

Running Test Programs: Advanced Options

Page 2: Google C++ Testing Framework

Two methodsEnvironment variables/

Command line flags◦Command –help or command /?

Flag in code

Page 3: Google C++ Testing Framework
Page 4: Google C++ Testing Framework

Disables elapsed time –command

Page 5: Google C++ Testing Framework

Default Execution Code

Page 6: Google C++ Testing Framework

Default Execution Results

Page 7: Google C++ Testing Framework

Flag in code - GTEST_FLAG

Page 8: Google C++ Testing Framework

Added Flag

Page 9: Google C++ Testing Framework

PriorityCommand line flags>Flag in code

Page 10: Google C++ Testing Framework

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:

Page 11: Google C++ Testing Framework

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_filter flag 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.

Page 12: Google C++ Testing Framework

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.

gtest_demo --gtest_repeat=1000 Repeat gtest_demo 1000 times and don't stop at failures.

gtest_demo --gtest_repeat=-1 A negative count means repeating forever.

gtest_demo --gtest_repeat=1000 --gtest_break_on_failure

Repeat gtest_demo1000 times, stopping at the first failure. This is especially useful when running under a debugger: when the testfails, it will drop into the debugger and you can then inspect variables and stacks.

gtest_demo --gtest_repeat=1000 --gtest_filter=FooBar

Repeat the tests whose name matches the filter 1000 times.

Page 13: Google C++ Testing Framework

Generating ReportsGoogle 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.

Page 14: Google C++ Testing Framework

Gtest_demo –gtest_output=xml

Page 15: Google C++ Testing Framework

Test_detail.xml

Page 16: Google C++ Testing Framework

Structure of XML

Page 17: Google C++ Testing Framework

Example

Page 18: Google C++ Testing Framework

NotesThe 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.