jeppeman / android-jetpack-playground

Pet project for cutting edge Android development with Jetpack
Apache License 2.0
271 stars 18 forks source link

Could I get an example of FragmentTest with viewModel injected instead of mocked? #2

Open di0n0s opened 5 years ago

di0n0s commented 5 years ago

Hi,

First of all, thank you very much for this repository. It´s very didactic and helps a lot to understand Android development with Jetpack.

I´m trying to testing one of my fragment without mocking viewModel because I need to do an acceptance test but I don't know why viewModel is not injecting. I think because I must setup dagger ready to use on espresso testing.

How would you setup your project to inject dependencies on espresso tests? Could I get an example of your "VideoListFragmentTest" with viewModel injected instead of mocked on a branch?

Thanks in advance!

jeppeman commented 4 years ago

Hi there!

Sorry for the late response, been out of the loop for a while. Glad the project has been of some help to you.

It sounds like you want to do an integration or end to end test; In this case you do not really want to incorporate the viewmodel in your test, you'd rather want to just use the espresso API:s to do things such as view actions / assertions or intent stubbing. Have a look at this test and see if that makes any sense. It basically clicks an item in the video list and checks that the detail page is displayed.

di0n0s commented 4 years ago

Hi there,

Sorry for delaying answering this! I had a release and I t was a really crazy month. Could you upload again the link with the example test? I get a 404 now.

Thanks in advance.