I have started a unit test including following properties:
Copy code
@RelaxedMockK
lateinit var connector: Connector
@SpyK
@InjectMockKs
lateinit var viewModel: ScanProcessorViewModel
How can I mock the
scanObservers
property and then verify that an entry has been added by the
init
block?
s
Sam
07/12/2023, 2:33 PM
I’m not sure you need mocks here. What problems do you run into if you just use real instances?
m
Mario Adam
07/12/2023, 3:10 PM
The code - of course - is snipped… The viewmodel for example has a few more stuff provided by its constructor. Mocking these is much more comfortable - given the fact that the concrete implementations are in another package (following onion architecture).
Of course - I could leave out the viewmodel property in my test and create it within my tests. This would make my
connector
able to be a concrete instance instead of a mock while the other stuff remains mocked.
Mario Adam
07/12/2023, 3:14 PM
OK - I need to revert my comment above. I need to mock the
connector
as well, as this class has an
init
block as well which does some concrete system calls (precisely: broadcasting intents)