Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
"AndroidViewModel causes subtle and unavoidable problems in Robolectric tests."
"Robolectric tests create a new Application instance for each test case. AndroidViewModel stashes the application instance in a static field during the execution of the first test case that runs, and retains it across test cases. This causes your test (and any Dagger dependencies) to use an inconsistent application context than your AndroidViewModel instances."
"This issue is easily mitigated. AndroidViewModel is simply a convenience to avoid creating a custom ViewModelProvider.Factory. To workaround this issue, just create a custom factory for your ViewModel."
I think it can be fixed by checking whether the mApplication of sInstance is different to the application passed into getInstance. If so, recreate the instance.