blob: 531f062f6bdc663fbe8c4d05ab45b35156679a1a [file] [log] [blame] [view]
Dirk Pranke78557c52020-09-26 19:04:091# On disabling tests
2
3Sometimes you don't want to run a test that you've written (or that
Dirk Pranke8b9103a2020-10-07 18:06:294you've imported, like conformance tests). The test might not be possible to
5run in a particular configuration, or be temporarily broken by another
6change, or be flaky, or simply not work yet. In these cases (and perhaps others),
7you should disable the test :).
Dirk Pranke78557c52020-09-26 19:04:098
Dirk Pranke8b9103a2020-10-07 18:06:299There are a number of different ways to do so:
Dirk Pranke78557c52020-09-26 19:04:0910
11* If the test is an entire binary or test suite, the first (and
Dirk Pranke8b9103a2020-10-07 18:06:2912 simplest) way is to simply not build (or build, but not run)
13 the test binary, of course. This makes sense for binaries that
14 are specific to particular build configurations (e.g., Android JUnit
15 tests don't need to be built on Windows).
Dirk Pranke78557c52020-09-26 19:04:0916
Dirk Pranke8b9103a2020-10-07 18:06:2917* A second way (for tests in C++) is to not compile a test in a
18 given configuration, e.g., `#ifndef WIN`. In this situation, the only
Dirk Pranke78557c52020-09-26 19:04:0919 way you would know the test existed and was disabled would be to
Dirk Pranke8b9103a2020-10-07 18:06:2920 parse the source code. We often do this today for tests that will
21 never be enabled in particular build configurations, but sometimes we do
22 this to temporarily skip tests as well.
Dirk Pranke78557c52020-09-26 19:04:0923
Dirk Pranke8b9103a2020-10-07 18:06:2924* A third way is to take advantage of features in your testing framework to
25 skip over tests. Examples include involve adding `DISABLED_` to the test
26 method name for GTest-based tests, `@unittest.skip` for Python-based tests,
27 or using the
28 [DisabledTest](../../base/test/android/javatests/src/org/chromium/base/test/DisabledTest.java)
Boris Sazonovc45f1312022-09-06 16:01:5029 annotation for JUnit-based Java tests (this works in both instrumentation
30 and Robolectric tests). In these cases, you don't run the test by default,
31 but you can determine the list of disabled tests at runtime because the
32 tests are present in the executable, and you may still be able to force the
33 test to be run via a command-line flag.
Dirk Pranke78557c52020-09-26 19:04:0934
Dirk Pranke8b9103a2020-10-07 18:06:2935* Fourth, for test frameworks that support
36 [expectations files or filter files](https://bit.ly/chromium-test-list-format),
37 you can use them to decide what to run and what to skip. This moves
38 the mechanisms out of the source code and into separate files; there are
39 advantages and disadvantages to this. The main advantage is that it
40 can make it easier to write tooling to disable tests, and the main
41 disadvantage is that it moves the mechanism away from the code it affects,
42 potentially making it harder to understand what's going on.
Dirk Pranke78557c52020-09-26 19:04:0943
Dirk Pranke8b9103a2020-10-07 18:06:2944* Finally, the test harness can run the test, but the test itself
45 might detect at runtime that it should exit early for some reason
46 rather than actually executing the code paths you'd normally want to
47 test. For example, if you have a test for some code path that requires
48 a GPU, but there's no GPU on the machine, the test might check for a
49 GPU and exit early with "success".
Dirk Pranke78557c52020-09-26 19:04:0950
Dirk Pranke8b9103a2020-10-07 18:06:2951If you want to be able to determine a global picture of which tests
52were disabled, you can either parse BUILD files, expectations and filter
53files, and source code to try and figure that out, or require the tests be
54present in test binaries (i.e., not compiled out) and then run the test
55binaries in order to collect the lists of disabled tests and report them
56to a central system.
Dirk Pranke78557c52020-09-26 19:04:0957
Dirk Pranke8b9103a2020-10-07 18:06:2958Parsing code can be straightforward for some types of tests, but
59difficult-to-impractical to do correctly for others.