2

I'm use MockK for unit test. How i can mockk private call with nullable and not nullable args?

My method:

private fun trySaveLogin(session: Session, login: String, passwordHash: String?, passwordHashNoSalt: String?, userInfo: UserInfo) { // doWork}

Already tried:

every { loginPresenter["trySaveLogin"](allAny<Any>())  } just Runs
every { loginPresenter["trySaveLogin"](any<String>(), any<String>(), any<String>(), any<String>(), any<UserInfo>()) } just Runs

Everything return error :

io.mockk.MockKException: can't find function trySaveLogin(-4d6de1423b10ebb8, ...) for dynamic call
darjke
  • 21
  • 1
  • 3
  • 1
    Don't know how to do that with MockK but if you end up mocking private methods, chances are that you have badly designed classes in your hands. – lelloman Nov 27 '18 at 08:37
  • Do you have a full stack trace and any other information from the exception? – Jayson Minard Nov 27 '18 at 11:58

1 Answers1

2

Use this:

every { loginPresenter["trySaveLogin"](any<Session>(), any<String>(), any<String>(), any<String>(), any<UserInfo>())  as Unit } just Runs
Vikas Jain
  • 73
  • 1
  • 8