Repository navigation
[TEST] Use gtest_discover_tests to prevent false-positive test passes - #4730
Open
Rajkaran-122 wants to merge 4 commits into
Open
Rajkaran-122 wants to merge 4 commits into
Rajkaran-122 wants to merge 4 commits into
Conversation
Fixes open-telemetry#4341 Replace gtest_add_tests() with gtest_discover_tests() across all test directories. The old approach scans source files at CMake configure time, so tests behind preprocessor conditionals remain registered in CTest even when compiled out. This causes CTest to report "Passed" for tests that never actually ran. gtest_discover_tests() queries the compiled test executable at build time, so compiled-out tests are never registered. This prevents false-positive passes and matches the behavior of the project's existing install tests. Migration includes: - SDK tests (metrics, trace, logs, common, configuration, resource, instrumentationscope) - API tests (all subdirectories) - Exporter tests (elasticsearch, etw, memory, ostream, otlp, prometheus, zipkin) - Extension tests (http, resource detectors) - OpenTracing shim tests - Installation verification tests Compatibility: - CMake minimum: 3.16 (gtest_discover_tests introduced in 3.10) - Discovery mode: POST_BUILD (default, compatible with CMake 3.16+) - GoogleTest: v1.17.0 (current pin) Note: This change runs test binaries at build time for discovery. Cross-compilation builds may need DISCOVERY_MODE PRE_TEST (requires CMake 3.26+) or separate test configurations.
Resolved merge conflicts in: - CHANGELOG.md: Kept open-telemetry#4341 entry in Unreleased section - exporters/etw/CMakeLists.txt: Kept gtest_discover_tests for all ETW tests - sdk/test/configuration/CMakeLists.txt: Kept gtest_discover_tests and preserved upstream target_link_libraries changes - sdk/test/instrumentationscope/CMakeLists.txt: Kept gtest_discover_tests and preserved upstream opentelemetry_instrumentation_scope library - sdk/test/logs/CMakeLists.txt: Kept gtest_discover_tests and preserved upstream opentelemetry_test_common linking - sdk/test/trace/CMakeLists.txt: Kept gtest_discover_tests and preserved upstream opentelemetry_test_common linking Deleted api/test/plugin/CMakeLists.txt (removed in upstream)
marcalff
reviewed
Oct 23, 2026
…cover_tests With gtest_discover_tests, tests are discovered at build time, not configure time. set_tests_properties cannot find tests that don't exist yet at configure time. Move the TIMEOUT properties directly into the gtest_discover_tests call for the specific tests that need them. Fixes: - sdk/test/trace/CMakeLists.txt: tracer_provider_test timeout - sdk/test/metrics/CMakeLists.txt: meter_provider_sdk_test timeout - sdk/test/logs/CMakeLists.txt: logger_provider_sdk_test timeout
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4730 +/- ##
=======================================
Coverage 86.70% 86.70%
=======================================
Files 527 527
Lines 20902 20902
=======================================
Hits 18121 18121
Misses 2781 2781 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4341
Replace gtest_add_tests() with gtest_discover_tests() across all test directories. The old approach scans source files at CMake configure time, so tests behind preprocessor conditionals remain registered in CTest even when compiled out. This causes CTest to report "Passed" for tests that never actually ran.
gtest_discover_tests() queries the compiled test executable at build time, so compiled-out tests are never registered. This prevents false-positive passes and matches the behavior of the project's existing install tests.
Migration includes:
Compatibility:
Note: This change runs test binaries at build time for discovery. Cross-compilation builds may need DISCOVERY_MODE PRE_TEST (requires CMake 3.26+) or separate test configurations.