airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.85k stars 499 forks source link

How to properly Unit test the State? #628

Closed martymiller closed 2 years ago

martymiller commented 2 years ago

I wrote some basic code (that most certainly doesn't compile) to reflect the problem I'm having. Since classes like ViewModelTest are not publicly released in the SDK, do you see a fix for the following code that will make the test pass?

Screen Shot 2022-04-28 at 12 22 24 PM

I should note that we are currently on an older version of MvRx (1.5.1)

@elihart

gpeal commented 2 years ago

The MvRxTestRule is for this https://github.com/airbnb/mavericks/blob/e8a631a19fc1b044da3ddff358712e129dc487a6/hellodagger/src/test/java/com/airbnb/mvrx/hellodagger/HelloDaggerViewModelTest.kt#L16

martymiller commented 2 years ago

thanks @gpeal

We actually have this line in our code as well. But I'm not sure what it does. mvrxRule doesn't get referenced in the above code or ours.

gpeal commented 2 years ago

It's a junit test rule that sets a synchronous setState reducer before the test runs