blob: 439b9c8b33f5675848d1430b00731c3cd18b3aaa [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)
29 annotation for JUnit-based Java tests. In these cases, you don't run the
30 test by default, but you can determine the list of disabled tests at
31 runtime because the tests are present in the executable, and you may still
32 be able to force the test to be run via a command-line flag.
Dirk Pranke78557c52020-09-26 19:04:0933
Dirk Pranke8b9103a2020-10-07 18:06:2934* Fourth, for test frameworks that support
35 [expectations files or filter files](https://bit.ly/chromium-test-list-format),
36 you can use them to decide what to run and what to skip. This moves
37 the mechanisms out of the source code and into separate files; there are
38 advantages and disadvantages to this. The main advantage is that it
39 can make it easier to write tooling to disable tests, and the main
40 disadvantage is that it moves the mechanism away from the code it affects,
41 potentially making it harder to understand what's going on.
Dirk Pranke78557c52020-09-26 19:04:0942
Dirk Pranke8b9103a2020-10-07 18:06:2943* Finally, the test harness can run the test, but the test itself
44 might detect at runtime that it should exit early for some reason
45 rather than actually executing the code paths you'd normally want to
46 test. For example, if you have a test for some code path that requires
47 a GPU, but there's no GPU on the machine, the test might check for a
48 GPU and exit early with "success".
Dirk Pranke78557c52020-09-26 19:04:0949
Dirk Pranke8b9103a2020-10-07 18:06:2950If you want to be able to determine a global picture of which tests
51were disabled, you can either parse BUILD files, expectations and filter
52files, and source code to try and figure that out, or require the tests be
53present in test binaries (i.e., not compiled out) and then run the test
54binaries in order to collect the lists of disabled tests and report them
55to a central system.
Dirk Pranke78557c52020-09-26 19:04:0956
Dirk Pranke8b9103a2020-10-07 18:06:2957Parsing code can be straightforward for some types of tests, but
58difficult-to-impractical to do correctly for others.