Closed mcomella closed 5 years ago
LiveData is tricky to test because you need to attach observers in order to assert the values received: this means the code cannot be written in an intuitive, sequential fashion. For example, on FFES I wrote:
viewModel.setIsVoiceViewEnabled(true) viewModel.setIsNavigationOverlayVisible(false) viewModel.isToolbarScrollEnabled.observeForever { assertFalse(it!!) } viewModel.setIsNavigationOverlayVisible(true)
(where ToolbarScrollEnabled is modified by changes in VoiceView and NavOverlay).
On FFTV, there's a test helper so that you can write tests like:
viewModel.isToolbarScrollEnabled.assertValues(false, false, false, false) { viewModel.setIsVoiceViewEnabled(true) viewModel.setIsNavigationOverlayVisible(false) viewModel.setIsNavigationOverlayVisible(true) }
The test helpers are defined here – https://github.com/mozilla-mobile/firefox-tv/blob/master/app/src/test/java/org/mozilla/tv/firefox/helpers/ext/LiveDataTestHelper.kt – and have their own tests here: https://github.com/mozilla-mobile/firefox-tv/blob/master/app/src/test/java/org/mozilla/tv/firefox/helpers/ext/LiveDataTestHelperTest.kt (which annoying run in the same test suite as the application tests).
We should use these helpers or adapt some new helpers.
┆Issue is synchronized with this Jira Task
afaik, all of our teams are moving towards Rx: I don't think this is necessary.
LiveData is tricky to test because you need to attach observers in order to assert the values received: this means the code cannot be written in an intuitive, sequential fashion. For example, on FFES I wrote:
(where ToolbarScrollEnabled is modified by changes in VoiceView and NavOverlay).
On FFTV, there's a test helper so that you can write tests like:
The test helpers are defined here – https://github.com/mozilla-mobile/firefox-tv/blob/master/app/src/test/java/org/mozilla/tv/firefox/helpers/ext/LiveDataTestHelper.kt – and have their own tests here: https://github.com/mozilla-mobile/firefox-tv/blob/master/app/src/test/java/org/mozilla/tv/firefox/helpers/ext/LiveDataTestHelperTest.kt (which annoying run in the same test suite as the application tests).
We should use these helpers or adapt some new helpers.
┆Issue is synchronized with this Jira Task