-
Notifications
You must be signed in to change notification settings - Fork 60
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
Proposal: Mocking notifications #26
Comments
This sounds like a great idea -- though I'm a little unsure about what the implementation would look like (My mocking knowledge is a little limited). Perhaps you can clarify or provide an example library which uses such an extension function? It seems that you would have to use the |
I could definitely contribute if you'd like 😄 Since you have: class Notify {
companion object {
fun with(context: Context): Notify {
...
}
}
} You could have another module, a test module, that declares something like this: fun Notify.Companion.withMock(context: Context): Notify {
...
} I was thinking you could integrate with Mockito like this: fun Notify.Companion.withMock(context: Context): Notify {
return Mockito.mock(Notify::class.java)
} However that wouldn't be automated and would require usage updates. So it would be nice if the existing Maybe there could be some sort of global property that would be set when a unit test or UI test is beginning to run. With that property set to true, the existing |
I'm always taking new contributions! Your proposal makes sense to me and I think I would be very beneficial. If you can throw up a PR I can take a look and we can get it merged in. Turns out that the if we want to mock the Notify.defaultConfig {
notificationManager = mockNotificationManager
...
} As long as this step is done during initialization, i.e prior to the first use of Let me know what you think! |
In apps I tend to give notification creation responsibility to injectable interface that has a "Real" implementation. The interface is mocked in my tests.
I could see this being a very big use case for this library in addition to the already great convenience. Since you're using Kotlin, this could just be an companion object extension that could be a
testImplementation
dependency. Something like:Internally, it would use Mockito or some internal class that isn't the real Android framework class.
The text was updated successfully, but these errors were encountered: