blob: 706e3bcca9f45418b6d204b8481ec877e3ee478f [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.
37
38
39The following table shows which types of test works on which platforms.
40
41| | Linux | Windows | Mac | Android | iOS | CrOS |
42|:----------------------------|:--------|:--------|:--------|:--------|:--------|:--------|
43| gtest(C++) | &#8730; | &#8730; | &#8730; | &#8730; | &#8730; | &#8730; |
44| Junit(Java) | | | | &#8730; | | |
45| Browser Tests(C++) | &#8730; | &#8730; | &#8730; | &#8730; | | |
46| Web Tests(HTML, JS) | &#8730; | &#8730; | &#8730; | | | |
47| Telemetry(Python) | &#8730; | &#8730; | &#8730; | &#8730; | | &#63; |
48| Instrumentation Tests(Java) | | | | &#8730; | | |
49| EarlGrey | | | | | &#8730; | |
50| Fuzzer Tests(C++) | &#8730; | &#8730; | &#8730; | &#8730; | | &#8730; |
51
52*** note
53**Browser Tests Note**
54
55Only subset of browser tests are enabled on Android:
56* components_browsertests
57* content_browsertests
58* nonperfetto_content_browsertests
59
60Other browser tests are not supported on Android yet. [crbug/611756]
61tracks the effort to enable them on Android.
62***
63
64*** note
65**Web Tests Note**
66
67Web Tests were enabled on Android K before, but it is disabled on Android platform now,
68see [this thread](https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/338WKwWPbPI/discussion) for more context.
69***
70
71*** note
72**Telemetry**
73
74Telemetry works on CrOS, but it is not officially supported yet.
75***
76
77*** note
78**CrOS Note**
79
80There is an on going effort to enable existing Chromium tests on CrOS VM hosted on Linux,
81right now only unit tests are enabled on CrOS VM.
82***
83
84## General Principles
85
86* All the tests in Chromium running on CQ and main waterfall should be hermetic and stable.
87* Add unit tests along with the code in same changelist instead of adding tests in future,
88 it is most likely no one will add tests later.
89* Write enough unit tests to have good [code coverage](./code_coverage.md),
90 since they are fast and stable.
91* Don't enable tests with external dependencies on CQ and main waterfall,
92 e.g. tests against live sites.
93 It is fine to check in those tests, but only run them on your own bots.
94
95## What tests are needed for new features
96
97* **Unit Tests** are needed no matter where the code is for your feature.
98 It is the best practice to add the unit tests
99 when you add new code or update existing code in the same changelist,
100 check out [Code Coverage in Gerrit](/code_coverage_in_gerrit.md)
101 for the instruction about how to see the code coverage in Gerrit.
102* **Browser Tests** are recommended for integration tests and e2e tests.
103 It will be great if you add browser tests to cover the major user
104 cases for your feature, even with some mocking.
105* **[Web Tests]** are required if you plan to launch new W3C APIs in Chrome.
106* **[Instrumentation Tests]** are recommended for features on Android, you only
107 need to write instrumentation features
108 if your feature is supported on Android for integration tests or e2e tests.
109* **EarlGrey Tests** are recommended for iOS only.
110* **[Telemetry] benchmarking or stories** are needed if existing telemetry
111 benchmarks or stories can't cover the performance for your feature,
112 you need to either add new story, but reuse existing metrics or
113 add new benchmarks for your feature. Talk to benchmarking team first
114 before start to add Telemetry benchmarks or stories.
115* **[Fuzzer Tests]** are recommended if your feature adds user facing APIs
116 in Chromium, it is recommended to write fuzzer tests to detect the security issue.
117
118Right now, code coverage is the only way we have to measure test coverage.
119The following is the recommended thresholds for different code coverage levels:
120* >level 1(improving): >0%
121* >level 2(acceptable): 60%
122* >level 3(commendable): 75%
123* >level 4(exemplary): 90%
124
125Go to [code coverage dashboard](https://analysis.chromium.org/p/chromium/coverage) to check the code coverage for your project.
126
127
128## How to write new tests
129* [Simple gtests]
130* [Writing JUnit tests]
131* [Writing Browser Tests]
132* [Writing Instrumentation Tests]
133* [Writing EarlGrey Tests]
134* [Writing Telemetry Benchmarks/Stories]
135* [Writing Web Tests](./writing_web_tests.md)
136* [Write Fuzz Target]
137
138>TODO: add the link to the instruction about how to enable new tests in CQ and main waterfall
139
140## How to run tests
141
142### Run tests locally
143* [Run gtest locally]
144* [Run browser tests locally]
145* [Run tests on Android](./android_test_instructions.md#Running-Tests)
146 It includes the instructions to run gTests, JUnit tests and Instrumentation tests on Android.
147* [Run EarlGrey tests locally](../ios/testing.md#running-tests-from-xcode)
148* [Run Web Tests locally](./testing/web_tests.md#running-web-tests)
149* [Telemetry: Run benchmarks locally]
150* [Run fuzz target locally]
151
152### Run tests remotely(on Swarming)
153>TODO: add the link to the instruction about how to run tests on Swarming.
154
155## How to debug tests
156* [Android Debugging Instructions]
157* [Debugging Web Tests]
158
159## How to deal with flaky tests
160
161Go to [Flaky portal] to find the report about the flaky tests in your projects.
162
163If you can not fix the flaky tests in a short time, consider to disable it first,
164then fix it later. [How do I disable a flaky test] is the instruction about how to disable a flaky test.
165
166>TODO: add the link to the instruction about how to reproduce/debug/verify flaky tests.
167
168
169[gtest]: https://github.com/google/googletest
170[Simple gtests]: https://github.com/google/googletest/blob/master/googletest/docs/primer.md#simple-tests
171[Junit]: https://developer.android.com/training/testing/junit-rules
172[Instrumentation Tests]: https://chromium.googlesource.com/chromium/src/+/master/testing/android/docs/instrumentation.md
173[EarlGrey]: https://github.com/google/EarlGrey
174[Telemetry]: https://chromium.googlesource.com/catapult/+/HEAD/telemetry/README.md
175[Fuzzer Tests]: https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/README.md
176[Web Tests]: ./web_tests.md
177[crbug/611756]: https://bugs.chromium.org/p/chromium/issues/detail?id=611756
178[Flaky portal]: https://analysis.chromium.org/p/chromium/flake-portal
179[Write Fuzz Target]: https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/getting_started.md#write-fuzz-target
180[Telemetry: Run benchmarks locally]: https://chromium.googlesource.com/catapult/+/HEAD/telemetry/docs/run_benchmarks_locally.md
181[Run fuzz target locally]: https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/getting_started.md#build-and-run-fuzz-target-locally
182[Android Debugging Instructions]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/android_debugging_instructions.md
183[Debugging Web Tests]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/testing/web_tests.md#Debugging-Web-Tests
184[code coverage dashboard]: https://analysis.chromium.org/p/chromium/coverage
185[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-