blob: eda1efc8ec28cb1d0a30aff7dc2ec434f4178121 [file] [log] [blame] [view]
Lei Lei75b4ff72019-08-21 19:03:541Testing is an essential component of software development in Chromium,
2it ensures Chrome is behaving as we expect, and is critical to find bugs and
3regressions at early stage.
4
5This document covers the high level overview of testing in Chromium,
6including what type of tests we have, what's the purpose for each test type,
7what tests are needed for new features etc.
8
9## Test Types
10
11There are several different types of tests in Chromium to serve different purposes,
12some types of test are running on multiple platforms, others are specific
13for one platform.
14
15* **[gtest]** is Google's C++ test framework,
16 which helps you write better C++ tests in Chromium.
17 gtest is test framework for unit tests in Chromium and browser tests are built on top of it.
18* **[Junit]** is a unit testing framework
19 for the Java programming language, and it is used to write
20 unit tests on Android for Java code in Chromium.
21* **Browser Tests** is built on top of gtest, and it is used to write integration tests
22 and e2e tests in Chromium.
23 <!-- TODO(leilei) Add link to browser tests --->
24* **[Web Tests] (formerly known as "Layout Tests" or "LayoutTests")**
25 is used by Blink to test many components, including but not
26 limited to layout and rendering. In general, web tests involve loading pages
27 in a test renderer (`content_shell`) and comparing the rendered output or
28 JavaScript output against an expected output file.
29 Web Tests are required to launch new W3C API support in Chromium.
30* **[Instrumentation Tests]** is a test framework specific for Android platform,
31 it is used to write integration tests or e2e tests for Chromium on Android.
32* **[EarlGrey]** is the integration testing framework used by Chromium for iOS.
33* **[Telemetry]** is the performance testing framework used by Chromium.
34 It allows you to perform arbitrary actions on a set of web pages and
35 report metrics about it.
36* **[Fuzzer Tests]** is used to uncover potential security & stability problems in Chromium.
Ben Pasteneb30c66e92019-08-30 23:25:1037* **[Tast]** is a test framework for system integration tests on Chrome OS.
Lei Lei75b4ff72019-08-21 19:03:5438
39
40The following table shows which types of test works on which platforms.
41
42| | Linux | Windows | Mac | Android | iOS | CrOS |
43|:----------------------------|:--------|:--------|:--------|:--------|:--------|:--------|
44| gtest(C++) | &#8730; | &#8730; | &#8730; | &#8730; | &#8730; | &#8730; |
45| Junit(Java) | | | | &#8730; | | |
46| Browser Tests(C++) | &#8730; | &#8730; | &#8730; | &#8730; | | |
47| Web Tests(HTML, JS) | &#8730; | &#8730; | &#8730; | | | |
Ben Pasteneb30c66e92019-08-30 23:25:1048| Telemetry(Python) | &#8730; | &#8730; | &#8730; | &#8730; | | &#8730; |
Lei Lei75b4ff72019-08-21 19:03:5449| Instrumentation Tests(Java) | | | | &#8730; | | |
50| EarlGrey | | | | | &#8730; | |
51| Fuzzer Tests(C++) | &#8730; | &#8730; | &#8730; | &#8730; | | &#8730; |
Ben Pasteneb30c66e92019-08-30 23:25:1052| Tast(Golang) | | | | | | &#8730; |
Lei Lei75b4ff72019-08-21 19:03:5453
54*** note
55**Browser Tests Note**
56
57Only subset of browser tests are enabled on Android:
58* components_browsertests
59* content_browsertests
60* nonperfetto_content_browsertests
61
62Other browser tests are not supported on Android yet. [crbug/611756]
63tracks the effort to enable them on Android.
64***
65
66*** note
67**Web Tests Note**
68
69Web Tests were enabled on Android K before, but it is disabled on Android platform now,
70see [this thread](https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/338WKwWPbPI/discussion) for more context.
71***
72
Lei Lei75b4ff72019-08-21 19:03:5473## General Principles
74
75* All the tests in Chromium running on CQ and main waterfall should be hermetic and stable.
76* Add unit tests along with the code in same changelist instead of adding tests in future,
77 it is most likely no one will add tests later.
78* Write enough unit tests to have good [code coverage](./code_coverage.md),
79 since they are fast and stable.
80* Don't enable tests with external dependencies on CQ and main waterfall,
81 e.g. tests against live sites.
82 It is fine to check in those tests, but only run them on your own bots.
83
84## What tests are needed for new features
85
86* **Unit Tests** are needed no matter where the code is for your feature.
87 It is the best practice to add the unit tests
88 when you add new code or update existing code in the same changelist,
89 check out [Code Coverage in Gerrit](/code_coverage_in_gerrit.md)
90 for the instruction about how to see the code coverage in Gerrit.
91* **Browser Tests** are recommended for integration tests and e2e tests.
92 It will be great if you add browser tests to cover the major user
93 cases for your feature, even with some mocking.
94* **[Web Tests]** are required if you plan to launch new W3C APIs in Chrome.
95* **[Instrumentation Tests]** are recommended for features on Android, you only
96 need to write instrumentation features
97 if your feature is supported on Android for integration tests or e2e tests.
98* **EarlGrey Tests** are recommended for iOS only.
99* **[Telemetry] benchmarking or stories** are needed if existing telemetry
100 benchmarks or stories can't cover the performance for your feature,
101 you need to either add new story, but reuse existing metrics or
102 add new benchmarks for your feature. Talk to benchmarking team first
103 before start to add Telemetry benchmarks or stories.
104* **[Fuzzer Tests]** are recommended if your feature adds user facing APIs
105 in Chromium, it is recommended to write fuzzer tests to detect the security issue.
106
107Right now, code coverage is the only way we have to measure test coverage.
108The following is the recommended thresholds for different code coverage levels:
109* >level 1(improving): >0%
110* >level 2(acceptable): 60%
111* >level 3(commendable): 75%
112* >level 4(exemplary): 90%
113
114Go to [code coverage dashboard](https://analysis.chromium.org/p/chromium/coverage) to check the code coverage for your project.
115
116
117## How to write new tests
118* [Simple gtests]
119* [Writing JUnit tests]
120* [Writing Browser Tests]
121* [Writing Instrumentation Tests]
122* [Writing EarlGrey Tests]
123* [Writing Telemetry Benchmarks/Stories]
124* [Writing Web Tests](./writing_web_tests.md)
125* [Write Fuzz Target]
126
127>TODO: add the link to the instruction about how to enable new tests in CQ and main waterfall
128
129## How to run tests
130
131### Run tests locally
132* [Run gtest locally]
133* [Run browser tests locally]
134* [Run tests on Android](./android_test_instructions.md#Running-Tests)
135 It includes the instructions to run gTests, JUnit tests and Instrumentation tests on Android.
136* [Run EarlGrey tests locally](../ios/testing.md#running-tests-from-xcode)
137* [Run Web Tests locally](./testing/web_tests.md#running-web-tests)
138* [Telemetry: Run benchmarks locally]
139* [Run fuzz target locally]
140
141### Run tests remotely(on Swarming)
142>TODO: add the link to the instruction about how to run tests on Swarming.
143
144## How to debug tests
145* [Android Debugging Instructions]
Ben Pasteneb30c66e92019-08-30 23:25:10146* [Chrome OS Debugging Tips]
Lei Lei75b4ff72019-08-21 19:03:54147* [Debugging Web Tests]
148
149## How to deal with flaky tests
150
151Go to [Flaky portal] to find the report about the flaky tests in your projects.
152
153If you can not fix the flaky tests in a short time, consider to disable it first,
154then fix it later. [How do I disable a flaky test] is the instruction about how to disable a flaky test.
155
156>TODO: add the link to the instruction about how to reproduce/debug/verify flaky tests.
157
158
159[gtest]: https://github.com/google/googletest
160[Simple gtests]: https://github.com/google/googletest/blob/master/googletest/docs/primer.md#simple-tests
161[Junit]: https://developer.android.com/training/testing/junit-rules
162[Instrumentation Tests]: https://chromium.googlesource.com/chromium/src/+/master/testing/android/docs/instrumentation.md
163[EarlGrey]: https://github.com/google/EarlGrey
164[Telemetry]: https://chromium.googlesource.com/catapult/+/HEAD/telemetry/README.md
165[Fuzzer Tests]: https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/README.md
Ben Pasteneb30c66e92019-08-30 23:25:10166[Tast]: https://chromium.googlesource.com/chromiumos/platform/tast/+/HEAD/README.md
Lei Lei75b4ff72019-08-21 19:03:54167[Web Tests]: ./web_tests.md
168[crbug/611756]: https://bugs.chromium.org/p/chromium/issues/detail?id=611756
169[Flaky portal]: https://analysis.chromium.org/p/chromium/flake-portal
170[Write Fuzz Target]: https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/getting_started.md#write-fuzz-target
171[Telemetry: Run benchmarks locally]: https://chromium.googlesource.com/catapult/+/HEAD/telemetry/docs/run_benchmarks_locally.md
172[Run fuzz target locally]: https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/getting_started.md#build-and-run-fuzz-target-locally
173[Android Debugging Instructions]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/android_debugging_instructions.md
Ben Pasteneb30c66e92019-08-30 23:25:10174[Chrome OS Debugging Tips]: ./chromeos_debugging_tips.md
Lei Lei75b4ff72019-08-21 19:03:54175[Debugging Web Tests]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/testing/web_tests.md#Debugging-Web-Tests
176[code coverage dashboard]: https://analysis.chromium.org/p/chromium/coverage
177[How do I disable a flaky test]: https://www.chromium.org/developers/tree-sheriffs/sheriff-details-chromium#TOC-How-do-I-disable-a-flaky-test-