lateinit-property-fakeauthrepository-has-not-been-initialized-unit-testing

444 views
Skip to first unread message

Yodgorbek Komilov

unread,
Sep 20, 2022, 9:26:26 AM9/20/22
to mockito

I am using unit testing when I run test I am getting following exception

lateinit property fakeAuthRepository has not been initialized kotlin.UninitializedPropertyAccessException: lateinit property fakeAuthRepository has not been initialized

below below my ViewModel test where test giving an exception

internal class SignInViewModelTest{ private val _login = MutableStateFlow<UiStateObject<SignInResponse>>(UiStateObject.EMPTY) @Mock lateinit var backendApi:BackendApi lateinit var fakeAuthRepository: FakeAuthRepository lateinit var authRepository: AuthRepository private lateinit var viewModel: SignInViewModel @Before fun setUp() { MockitoAnnotations.initMocks(this) fakeAuthRepository = FakeAuthRepository(backendApi) authRepository = AuthRepository(backendApi) viewModel = SignInViewModel(authRepository) } var login = _login @Test fun `testing repository`() = runBlockingTest { val fake = fakeAuthRepository.login("kyodg...@gmail.com", "12345678", "android", "123455") val real = authRepository.login("kyodg...@gmail.com", "12345678", "android", "123455") assertEquals(fake, real) } }

Reply all
Reply to author
Forward
0 new messages