-
Notifications
You must be signed in to change notification settings - Fork 211
Description
Description
It's difficult to write unit tests for Bugsnag functions due to how the SDK is built and how the Client is initialized/managed.
#103 describes a solution - building a wrapper class around the Bugsnag SDK and mocking that in tests - which is a good strategy that works well for most testing use cases. However, when we want to actually unit test our Bugsnag SDK wrapper class, we need a way to mock Bugsnag's internals, which is difficult to do today (especially in a plain JVM unit test without access to Android APIs/Context/etc.
Describe the solution you'd like
The ability to set an arbitrary Client implementation within Bugsnag, so that Bugsnag.addOnError and/or Bugsnag.notify can be called without the SDK complaining about start not being called (or requiring an API key).
If Client was an interface that we could override, I think that would be a great start.
Additionally, it would be even better if there was an optional bugsnag-test artifact that provided a MockClient implementation to use and assert upon in tests.
Describe alternatives you've considered
- Static mocks on
ContextandBugsnag, essentially mimicking the behavior of the SDK and setting no-op's or reasonable defaults. This works, but it's tedious. - The recommendation in this comment (always set up the SDK with the API key, and just use release stages to gate the error upload functionality)
- This is closest to the approach we landed on
Additional context
N/A