chromium - 測試工程的位置
阿新 • • 發佈:2018-12-15
前言
以前就想知道chromium工程中,哪個才是可以執行的測試工程。今天查資料時,找到了。
實驗
編譯出來的PE檔案為:Z:\chromium\src\out\my_x86_d\browser_tests.exe
直接執行,測試用例8000+。
browser_tests.exe 支援 --help命令列, 可以選擇自己要測試的子類別。最重要的是,通過測試程式,後續可以找到測試程式碼的實現,看看每一個知識點,作者是怎麼寫的呼叫程式碼。
.\browser_tests.exe --help Runs tests using the gtest framework, each batch of tests being run in their own process. Supported command-line flags: Common flags: --gtest_filter=... Runs a subset of tests (see --gtest_help for more info). --help Shows this message. --gtest_help Shows the gtest help message. --test-launcher-jobs=N Sets the number of parallel test jobs to N. --single_process Runs the tests and the launcher in the same process. Useful for debugging a specific test in a debugger. Other flags: --test-launcher-retry-limit=N Sets the limit of test retries on failures to N. --test-launcher-summary-output=PATH Saves a JSON machine-readable summary of the run. --test-launcher-print-test-stdio=auto|always|never Controls when full test output is printed. auto means to print it when the test failed. --test-launcher-total-shards=N Sets the total number of shards to N. --test-launcher-shard-index=N Sets the shard index to run to N (from 0 to TOTAL - 1).
.\browser_tests.exe --gtest_help
This program contains tests written using Google Test. You can use the
following command line flags to control its behavior:
Test Selection:
--gtest_list_tests
List the names of all tests instead of running them. The name of
TEST(Foo, Bar) is "Foo.Bar".
--gtest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS]
Run only the tests whose name matches one of the positive patterns but
none of the negative patterns. '?' matches any single character; '*'
matches any substring; ':' separates two patterns.
--gtest_also_run_disabled_tests
Run all disabled tests too.
Test Execution:
--gtest_repeat=[COUNT]
Run the tests repeatedly; use a negative count to repeat forever.
--gtest_shuffle
Randomize tests' orders on every iteration.
--gtest_random_seed=[NUMBER]
Random number seed to use for shuffling test orders (between 1 and
99999, or 0 to use a seed based on the current time).
Test Output:
--gtest_color=(yes|no|auto)
Enable/disable colored output. The default is auto.
--gtest_print_time=0
Don't print the elapsed time of each test.
--gtest_output=(json|xml)[:DIRECTORY_PATH\|:FILE_PATH]
Generate a JSON or XML report in the given directory or with the given
file name. FILE_PATH defaults to test_details.xml.
Assertion Behavior:
--gtest_break_on_failure
Turn assertion failures into debugger break-points.
--gtest_throw_on_failure
Turn assertion failures into C++ exceptions for use by an external
test framework.
--gtest_catch_exceptions=0
Do not report exceptions as test failures. Instead, allow them
to crash the program or throw a pop-up (on Windows).
Except for --gtest_list_tests, you can alternatively set the corresponding
environment variable of a flag (all letters in upper-case). For example, to
disable colored text output, you can either specify --gtest_color=no or set
the GTEST_COLOR environment variable to no.
For more information, please read the Google Test documentation at
https://github.com/google/googletest/. If you find a bug in Google Test
(not one in your own code or tests), please report it to
< [email protected]>.
列出測試子集的名稱
.\browser_tests.exe --gtest_list_tests PlatformAppBrowserTest. # TypeParam = RunningAppsAreRecorded # GetParam() = ActiveAppsAreRecorded # GetParam() = FileAccessIsSavedToPrefs # GetParam() = DISABLED_FileAccessIsRestored # GetParam() = LoadAndLaunchAppChromeRunning # GetParam() = LoadAndLaunchAppWithFile # GetParam() = CreateAndCloseAppWindow # GetParam() = ... MimeHandlerViewTests/MimeHandlerViewTest. PostMessageW/0 # GetParam() = false PostMessageW/1 # GetParam() = true Basic/0 # GetParam() = false Basic/1 # GetParam() = true Embedded/0 # GetParam() = false Embedded/1 # GetParam() = true Iframe/0 # GetParam() = false Iframe/1 # GetParam() = true Abort/0 # GetParam() = false Abort/1 # GetParam() = true NonAsciiHeaders/0 # GetParam() = false NonAsciiHeaders/1 # GetParam() = true DataUrl/0 # GetParam() = false DataUrl/1 # GetParam() = true EmbeddedDataUrlObject/0 # GetParam() = false EmbeddedDataUrlObject/1 # GetParam() = true EmbeddedDataUrlEmbed/0 # GetParam() = false EmbeddedDataUrlEmbed/1 # GetParam() = true EmbeddedDataUrlLong/0 # GetParam() = false EmbeddedDataUrlLong/1 # GetParam() = true ResizeBeforeAttach/0 # GetParam() = false ResizeBeforeAttach/1 # GetParam() = true SingleRequest/0 # GetParam() = false SingleRequest/1 # GetParam() = true BackgroundPage/0 # GetParam() = false BackgroundPage/1 # GetParam() = true
測試一個子集
從上面的子集合列表中取自己想測試的子集,跟在--gtest_filter=後面測試。
.\browser_tests.exe --gtest_filter=BackgroundPage/1
IMPORTANT DEBUGGING NOTE: each test is run inside its own process.
For debugging a test inside a debugger, use the
--gtest_filter=<your_test_name> flag along with either
--single_process (to run the test in one launcher/browser process) or
--single-process (to do the above, and also run Chrome in single-process mode).
Using sharding settings from environment. This is shard 0/1
Using 1 parallel jobs.
0 tests run
看測試程式打出的日誌,好像測試並沒有執行。
其實可以單步看看,就知道為啥不執行測試用例了。改天吧。