Skip to content

[TEST] Use gtest_discover_tests to prevent false-positive test passes - #4730

Open
Rajkaran-122 wants to merge 4 commits into
open-telemetry:mainfrom
Rajkaran-122:fix/ctest-false-positive-gtest
Open

Rajkaran-122 wants to merge 4 commits into
open-telemetry:mainfrom
Rajkaran-122:fix/ctest-false-positive-gtest

Conversation

@Rajkaran-122

@Rajkaran-122 Rajkaran-122 commented Oct 23, 2026 •

Copy link
Copy Markdown

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:

  • 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.

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.
@Rajkaran-122
Rajkaran-122 requested a review from a team as a code owner October 23, 2026 11:13
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)
Comment thread CHANGELOG.md Outdated
…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

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.70%. Comparing base (307a69b) to head (3fed106).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] CTest reports a pass for gtest cases the binary does not contain

2 participants