Skip to content
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

Unit Testing Triage: Issue while mocking Novu object #75

Open
therealansh opened this issue May 16, 2024 · 3 comments
Open

Unit Testing Triage: Issue while mocking Novu object #75

therealansh opened this issue May 16, 2024 · 3 comments

Comments

@therealansh
Copy link
Contributor

Hey folks, i am trying to write some UTs around my Novu service class. For that i am using mockito to mock the behavior of Novu. However, I am blocked because the APIs are marked as internal which makes is accessible only to its project scope. Any workaround i can do to mock Novu and do something like this:

@Mock
private lateinit var novu: Novu

@InjectMocks
private lateinit var notifService: NotifService

...

@Test
fun `test-success`() = runTest {
    whenever(novu.subscribers()).thenReturn(...)     <---------- this is where it throws NPE because subscriberApi isnt mocked and is internal
    notifService.getSubscribers()
}

@therealansh
Copy link
Contributor Author

@mayorJAY
Copy link
Contributor

mayorJAY commented May 16, 2024

All the publicly accessible functions in this SDK are extension functions, try using mockk or mockito-kotlin to mock extension functions. That will solve the problem. See https://stackoverflow.com/questions/44382540/mocking-extension-function-in-kotlin

@mayorJAY
Copy link
Contributor

@therealansh Is this resolved?

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

No branches or pull requests

2 participants