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

ViewModel unit tests #13

Open
rsetkus opened this issue Mar 6, 2022 · 5 comments
Open

ViewModel unit tests #13

rsetkus opened this issue Mar 6, 2022 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@rsetkus
Copy link

rsetkus commented Mar 6, 2022

Hi,

Really like the implementation but I am struggling to find a way how to test view models. To be precise, how you would assert all values set to compose State<T> instance. Any ideas?

@rsetkus
Copy link
Author

rsetkus commented Mar 12, 2022

Hi @catalinghita8. Any ideas on above?

@catalinghita8
Copy link
Owner

Hi @rsetkus and sorry for the late response.
Asserting values of a State<*> object should be pretty straightforward. You can check out an example here.

Additional resource here.

@rsetkus
Copy link
Author

rsetkus commented Mar 25, 2022

Hi @catalinghita8. Thanks for the links. That was very useful.

I've read your artice and really liked it. Decided to give it a try and implement it on my own. However, it seems quite different compared to the implementation you provided above. I've applied the same workaround but it didn't work. State<*> doesn't accumulate any values.

Apparently it is known issue to Google and they expect to implement an API which would be capable to write all values written to State<*>

Warning: There are no current APIs to wait for writes to State objects in tests.

Do you have any ideas why given implementation unit tests implemented by example isn't working?

@catalinghita8
Copy link
Owner

I might have to investigate why with this particular architecture has issues on asserting State<*> values.
Have you tried defining some tests where the State abstraction is removed?

@catalinghita8 catalinghita8 added bug Something isn't working good first issue Good for newcomers labels Mar 25, 2022
@rsetkus
Copy link
Author

rsetkus commented Mar 25, 2022

The way how I imagine testing MVI view model is to assert written values to State by given Intent. Surely, you could replace State with something else, for instance, LiveData and that might work. However, working with Compose and having only State exposed as output in the view model, is pretty neat. This is why I love your article. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants