Skip to content

Fix #2983: Fix self-referential test assertions in serialization round-trip tests#3242

Merged
0xnm merged 1 commit into
developfrom
mconstantin/2983/fix-wrong-test-assertions
Mar 11, 2026
Merged

Fix #2983: Fix self-referential test assertions in serialization round-trip tests#3242
0xnm merged 1 commit into
developfrom
mconstantin/2983/fix-wrong-test-assertions

Conversation

@mariusc83

Copy link
Copy Markdown
Member

Issue

Fixes #2983: Some tests always pass due to wrong assertion

GitHub Issue: #2983

Root Cause Analysis

All 11 serialization round-trip tests used self-referential assertions (assertThat(result).isEqualTo(result)) instead of comparing the deserialized result against the original input. This made the tests tautological — they always passed regardless of whether toJson()/fromJson() worked correctly.

Changes

Changed all 11 test assertions from assertThat(result).isEqualTo(result) to assertThat(result.toJson().toString()).isEqualTo(json), which validates that JSON data survives a full round-trip through fromJson()/toJson().

The JSON string comparison approach was chosen over object equality (isEqualTo(event)) because:

  • Some generated model classes (e.g., SpanEvent.Span) are not data class and lack equals() implementations
  • JSON type coercion (Long → Double) causes false equality failures even for data classes

Files Changed

File Change
ActionEventTest.kt Fix assertion to compare JSON strings
ErrorEventTest.kt Fix assertion to compare JSON strings
LongTaskEventTest.kt Fix assertion to compare JSON strings
ResourceEventTest.kt Fix assertion to compare JSON strings
ViewEventTest.kt Fix assertion to compare JSON strings
TelemetryDebugEventTest.kt Fix assertion to compare JSON strings
TelemetryErrorEventTest.kt Fix assertion to compare JSON strings
NetworkInfoTest.kt Fix assertion to compare JSON strings
UserInfoTest.kt Fix assertion to compare JSON strings
LogEventTest.kt Fix assertion to compare JSON strings
SpanEventTest.kt Fix assertion to compare JSON strings

Test Coverage

  • Tests fixed: 11 (across 4 modules: core, rum, logs, trace)
  • Local verification: core (PASS), logs (PASS), trace (PASS)
  • Note: RUM module has a pre-existing compilation error (RumVitalAppLaunchEvent redeclaration) on develop, unrelated to this change

Investigation Log

Issue Analysis

The issue reporter identified that multiple test files contained assertThat(result).isEqualTo(result) which always passes. This was confirmed across 11 files in 4 modules (2 more than originally reported).

Reproduction

All 11 affected files follow the same pattern: forge a random event, serialize to JSON, deserialize, and compare. The self-referential assertion never catches serialization bugs.

Fix Approach

  1. First attempted assertThat(result).isEqualTo(event) — this revealed real serialization differences (non-data-class types, JSON type coercion)
  2. Switched to JSON string comparison which correctly validates round-trip fidelity without depending on object equals()

…d-trip tests

Root cause: 11 test files used assertThat(result).isEqualTo(result) instead of
actually comparing the deserialized result against the original input, making
the tests tautological (always passing regardless of correctness).

Changes:
- Replace self-referential assertions with JSON string comparison
- assertThat(result.toJson().toString()).isEqualTo(json) validates
  that JSON survives a full round-trip through fromJson()/toJson()

Tests: 11 test files fixed across 4 modules (core, rum, logs, trace)
Verified: core (PASS), logs (PASS), trace (PASS), rum (BLOCKED by pre-existing compile error)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@datadog-datadog-prod-us1

This comment has been minimized.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.39%. Comparing base (8e4a988) to head (c5e158a).
⚠️ Report is 8 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3242      +/-   ##
===========================================
- Coverage    71.40%   71.39%   -0.01%     
===========================================
  Files          938      938              
  Lines        34667    34667              
  Branches      5874     5874              
===========================================
- Hits         24753    24749       -4     
- Misses        8263     8272       +9     
+ Partials      1651     1646       -5     

see 40 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mariusc83
mariusc83 marked this pull request as ready for review March 10, 2026 09:32
@mariusc83
mariusc83 requested review from a team as code owners March 10, 2026 09:32
@0xnm
0xnm merged commit 427ead9 into develop Mar 11, 2026
27 checks passed
@0xnm
0xnm deleted the mconstantin/2983/fix-wrong-test-assertions branch March 11, 2026 09:24
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.

Some tests always pass due to wrong assertion

4 participants