Skip to content

test: expand unit test coverage for public API and serialisation#314

Merged
TheRealAgentK merged 1 commit into
developfrom
test/expand-unit-test-coverage
May 4, 2026
Merged

test: expand unit test coverage for public API and serialisation#314
TheRealAgentK merged 1 commit into
developfrom
test/expand-unit-test-coverage

Conversation

@TheRealAgentK
Copy link
Copy Markdown
Contributor

test: expand unit test coverage for public API and serialisation

Description 📝

  • Purpose: A coverage gap audit of test/raygun4flutter_test.dart showed that several public-API surfaces and JSON-serialisation contracts had no tests at all (global tags/customData merging, custom endpoints, breadcrumb fields, user info round-trip, the offline & 429 retry branches, etc.). This PR closes the most impactful gaps without touching any production code.
  • Approach: Add 20 focused unit tests using the existing MockClient pattern, plus a few small setUp improvements so per-test state (global tags, custom data, breadcrumbs, custom endpoint) is reliably reset and so we can assert on request.url and call counts. No production code is changed; no .g.dart regeneration is needed.

Type of change

  • New feature (non-breaking change which adds functionality) — test-only additions

Updates

👉 20 new unit tests in test/raygun4flutter_test.dart — coverage moves from 15 → 35 tests.
👉 setUp now resets Settings.tags, Settings.customData, Settings.breadcrumbs and Settings.crashReportingEndpoint between tests; the MockClient now also captures request.url and a callCount for URL/call-count assertions.
👉 Side discovery filed as #313 — generated RaygunErrorMessage.toJson() returns the nested innerError as a raw object instead of a Map. Production wire format is unaffected (because everything goes through jsonEncode), so no fix needed in this PR; the affected test (nested innerError chain serialises to depth >1) round-trips through jsonEncode/jsonDecode to work around it.

Tests added

Area Test
Public API global tags merge with per-call tags
Public API setTags(null) clears global tags
Public API global customData merges with per-call customData
Public API setUser with full RaygunUserInfo
Public API setUser(null) resets to anonymous user
Public API setCustomCrashReportingEndpoint changes request URL
Public API setCustomCrashReportingEndpoint(null) restores default
Public API clearBreadcrumbs empties the buffer
Public API sendException passes explicit stackTrace through
Public API init called twice replaces the apiKey and version
Serialisation RaygunBreadcrumbLevel round-trips as string for every value
Serialisation breadcrumb category / customData / className / etc. round-trip
Serialisation RaygunUserInfo round-trips through JSON
Serialisation stack-trace lines serialise with expected keys
Serialisation nested innerError chain serialises to depth >1 (see #313)
Behavioural onBeforeSend can mutate tags before send
Behavioural onBeforeSend returning payload unchanged sends as-is
Behavioural offline path stores instead of sending
Behavioural 429 response retains the payload for retry
Behavioural sendAllStored happy path re-sends and clears the cache

Test plan 🧪

flutter pub get
dart format --set-exit-if-changed .
flutter analyze
flutter test

Expected:

  • format: clean
  • analyze: No issues found!
  • tests: 35/35 passed (was 15)

CI also covers the example builds for Android, iOS, macOS, Linux, Web (JS) and Web (WASM); none of those are affected because no production code changed.

Author to check 👓

  • Project and all contained modules builds successfully
  • Self-/dev-tested
  • Unit/UI/Automation/Integration tests provided where applicable
  • Code is written to standards
  • Appropriate documentation written (code comments, internal docs)

Reviewer to check ✔️

  • Project and all contained modules builds successfully
  • Change has been dev-/reviewer-tested, where possible
  • Unit/UI/Automation/Integration tests provided where applicable
  • Code is written to standards
  • Appropriate documentation written (code comments, internal docs)

Adds 20 new tests covering previously-untested behaviour:

Public API:
- Global setTags / setCustomData merge with per-call values
- setTags(null) / setUser(null) / setCustomCrashReportingEndpoint(null) reset paths
- setUser with full RaygunUserInfo (identifier, email, firstName, fullName)
- setCustomCrashReportingEndpoint changes the actual request URL
- clearBreadcrumbs empties the buffer
- sendException honours an explicit stackTrace argument
- init called twice swaps apiKey and version cleanly

Serialisation:
- RaygunBreadcrumbLevel round-trips as a string for every enum value
- RaygunBreadcrumbMessage optional fields (category, customData, className,
  methodName, lineNumber, timestamp) round-trip
- RaygunUserInfo round-trips through JSON
- Stack-trace lines serialise with the expected keys
- Nested innerError chains serialise correctly to depth >1 (see #313)

Behavioural / edge cases:
- onBeforeSend can mutate non-error fields (e.g. tags) before send
- onBeforeSend returning the payload unchanged sends as-is
- Offline path (ConnectivityResult.none) stores instead of sending
- 429 response retains the payload in the cache for retry
- sendAllStored happy path re-posts every cached payload and clears the cache

Also hardens setUp to reset Settings.tags / customData / breadcrumbs /
crashReportingEndpoint between tests, and captures request.url and a callCount
on the MockClient so URL- and call-count-based assertions are possible.
@TheRealAgentK TheRealAgentK merged commit dbd3d94 into develop May 4, 2026
8 checks passed
@TheRealAgentK TheRealAgentK mentioned this pull request May 4, 2026
11 tasks
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.

2 participants