test: expand unit test coverage for public API and serialisation#314
Merged
Conversation
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.
ProRedCat
approved these changes
May 4, 2026
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.
test: expand unit test coverage for public API and serialisation
Description 📝
test/raygun4flutter_test.dartshowed 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.MockClientpattern, plus a few smallsetUpimprovements so per-test state (global tags, custom data, breadcrumbs, custom endpoint) is reliably reset and so we can assert onrequest.urland call counts. No production code is changed; no.g.dartregeneration is needed.Type of change
Updates
👉 20 new unit tests in
test/raygun4flutter_test.dart— coverage moves from 15 → 35 tests.👉
setUpnow resetsSettings.tags,Settings.customData,Settings.breadcrumbsandSettings.crashReportingEndpointbetween tests; theMockClientnow also capturesrequest.urland acallCountfor URL/call-count assertions.👉 Side discovery filed as #313 — generated
RaygunErrorMessage.toJson()returns the nestedinnerErroras a raw object instead of aMap. Production wire format is unaffected (because everything goes throughjsonEncode), so no fix needed in this PR; the affected test (nested innerError chain serialises to depth >1) round-trips throughjsonEncode/jsonDecodeto work around it.Tests added
setTags(null)clears global tagssetUserwith fullRaygunUserInfosetUser(null)resets to anonymous usersetCustomCrashReportingEndpointchanges request URLsetCustomCrashReportingEndpoint(null)restores defaultclearBreadcrumbsempties the buffersendExceptionpasses explicitstackTracethroughinitcalled twice replaces the apiKey and versionRaygunBreadcrumbLevelround-trips as string for every valuecategory/customData/className/ etc. round-tripRaygunUserInforound-trips through JSONinnerErrorchain serialises to depth >1 (see #313)onBeforeSendcan mutate tags before sendonBeforeSendreturning payload unchanged sends as-issendAllStoredhappy path re-sends and clears the cacheTest plan 🧪
Expected:
No issues found!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 👓
Reviewer to check ✔️