-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to override/mock the Client #1810
Comments
Hi @erawhctim, We are giving this some consideration and we have added an item to the backlog to add some additional in depth information to our docs around our recommended ways on how to mock BugSnag. Appreciate it may be a little tedious in places but for now our recommended suggestion would be to use static mocks and utility methods, like you suggested. We will post here with updates. |
Ok, that makes sense. Thanks for the update! |
Has any internal discussion moved forward on this? Or is mocking still the preferred method of replacing BugSnag SDK functionality in tests? |
Hi @erawhctim Thanks for bumping this. We still don't have anything scheduled, but it would good to get a clear idea of what will help. We'd ideally like to keep any "test specific" logic out of BugsnagTesting.setGlobalClient(myMockedClient)
BugsnagTesting.clearGlobalClient() Would that be enough? Or would you need some other functionality? |
That would be great! I agree that offering a separate testing client makes the most sense 💯 Ideal use case (IMO):
Right now there isn't any other functionality we would need; all the |
Unfortunately we're not likely to make Other than |
got it, ok. Yeah if we still need to rely on Mocking tools to control a test-specific instance of |
Description
It's difficult to write unit tests for
Bugsnag
functions due to how the SDK is built and how theClient
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 withinBugsnag
, so thatBugsnag.addOnError
and/orBugsnag.notify
can be called without the SDK complaining aboutstart
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 aMockClient
implementation to use and assert upon in tests.Describe alternatives you've considered
Context
andBugsnag
, essentially mimicking the behavior of the SDK and setting no-op's or reasonable defaults. This works, but it's tedious.Additional context
N/A
The text was updated successfully, but these errors were encountered: