1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_CHECK_IS_TEST_H_
6 #define BASE_CHECK_IS_TEST_H_
8 #include "base/base_export.h"
10 // Code paths taken in tests are sometimes different from those taken in
11 // production. This might be because the respective tests do not initialize some
12 // objects that would be required for the "normal" code path.
14 // Ideally, such code constructs should be avoided, so that tests really test
15 // the production code and not something different.
17 // However, there already are hundreds of test-only paths in production code
18 // Cleaning up all these cases retroactively and completely avoiding such cases
19 // in the future seems unrealistic.
21 // Thus, it is useful to prevent the test code-only paths to be taken in
22 // production scenarios.
24 // `CHECK_IS_TEST` can be used to assert that a test-only path is actually taken
25 // only in tests. For instance:
27 // // This only happens in unit tests:
28 // if (!url_loader_factory)
30 // // Assert that this code path is really only taken in tests.
35 // `CHECK_IS_TEST` is thread safe.
37 #define CHECK_IS_TEST() base::internal::check_is_test_impl()
39 namespace base::internal {
40 BASE_EXPORT void check_is_test_impl();
41 } // namespace base::internal
43 #endif // BASE_CHECK_IS_TEST_H_