Skip to content

Conversation

@philipphofmann
Copy link
Member

@philipphofmann philipphofmann commented Jan 20, 2026

Applied Arrange-Act-Assert pattern with comment markers and made tests DAMP by inlining the helper method.

Changes

  • Added // -- Arrange --, // -- Act --, // -- Assert -- comment markers
  • Inlined assertDescription helper to make each test self-contained
  • Added constants for magic numbers (midRangeMultiplier, maxValueOffset)
  • Used descriptive variable names (singleUnitResult, midRangeResult, maxValueResult)

Rationale

DAMP tests are more readable and maintainable - each test can be understood independently without navigating to helper methods.

#skip-changelog

Closes #7222

Refactored SentryByteCountFormatterTests to follow Arrange-Act-Assert
pattern with explicit comment markers. Inlined helper method to make
tests DAMP (Descriptive And Meaningful Phrases) - each test is now
self-contained and readable without jumping to helper methods.

Added descriptive constants (midRangeMultiplier, maxValueOffset) and
variable names (singleUnitResult, midRangeResult, maxValueResult) to
eliminate magic numbers and improve clarity.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@philipphofmann philipphofmann added the ready-to-merge Use this label to trigger all PR workflows label Jan 20, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.076%. Comparing base (d8db577) to head (3c2da32).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7221       +/-   ##
=============================================
+ Coverage   85.062%   85.076%   +0.014%     
=============================================
  Files          468       468               
  Lines        28305     28305               
  Branches     12532     12536        +4     
=============================================
+ Hits         24077     24081        +4     
+ Misses        4183      3962      -221     
- Partials        45       262      +217     

see 28 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8db577...3c2da32. Read the comment docs.

@philipphofmann philipphofmann marked this pull request as draft January 20, 2026 10:27
philipphofmann added a commit that referenced this pull request Jan 20, 2026
Removed maxValueOffset constant that incorrectly changed test semantics.
The original expression 'baseValue * 1_024 - 1' evaluates as
'(baseValue * 1_024) - 1', testing true boundary values. The extracted
constant 'maxValueOffset = 1_024 - 1' changed this to 'baseValue * 1_023',
producing incorrect test values.

Addresses feedback: #7221 (comment)
@philipphofmann philipphofmann force-pushed the test/aaa-pattern-damp-byte-count-formatter branch 2 times, most recently from 0db46aa to abb377a Compare January 20, 2026 12:27
@philipphofmann
Copy link
Member Author

Fixed! Changed from the incorrect constant extraction to using inline expression baseValue * kbSize - 1 which correctly preserves operator precedence: (baseValue * kbSize) - 1.

Also updated constant names to halfKb and kbSize for clarity.

Refactored SentryByteCountFormatterTests to follow Arrange-Act-Assert
pattern with explicit comment markers. Inlined helper method to make
tests DAMP (Descriptive And Meaningful Phrases) - each test is now
self-contained and readable without jumping to helper methods.

Added descriptive constants (halfKbSize, kbSize) and variable names
(singleUnitResult, midRangeResult, maxValueResult) to eliminate
magic numbers and improve clarity.

Fixed operator precedence for boundary value calculation - using
'baseValue * kbSize - 1' preserves correct semantics.
@philipphofmann philipphofmann force-pushed the test/aaa-pattern-damp-byte-count-formatter branch from abb377a to 3c2da32 Compare January 20, 2026 12:30
@philipphofmann philipphofmann marked this pull request as ready for review January 20, 2026 12:30
private let halfKbSize: UInt = 512
private let kbSize: UInt = 1_024

func testBytesDescription() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: I feel like this is great opportunity to adopt our Test Naming Convention:

#### Test Naming Convention

Use the pattern `test<Function>_when<Condition>_should<Expected>()` for test method names:

**Format:** `test<Function>_when<Condition>_should<Expected>()`

**Examples:**

- ✅ `testAdd_whenSingleItem_shouldAppendToStorage()`
- ✅ `testAdd_whenMaxItemCountReached_shouldFlushImmediately()`
- ✅ `testCapture_whenEmptyBuffer_shouldDoNothing()`
- ✅ `testAdd_whenBeforeSendItemReturnsNil_shouldDropItem()`

**Benefits:**

- Clear function being tested
- Explicit condition/scenario
- Expected outcome is obvious
- Easy to understand test purpose without reading implementation

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

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: apply AAA pattern and DAMP to SentryByteCountFormatterTests

3 participants