我已经将isGpsEnabled
设置为false,但是当我调试测试时,它仍然显示为true。我不知道为什么会这样。
@Before
fun setupViewModel() {
preferences = FakePreferences()
connectivityObserver = FakeConnectivityObserver()
locationRepository = FakeLocationRepository()
weatherRepository = FakeWeatherRepository()
weatherUseCase = WeatherUseCases(
getAllWeather = GetAllWeather(weatherRepository),
convertUnit = ConvertUnit(),
)
locationUseCases = LocationUseCases(
ValidateCurrentLocation(locationRepository, preferences),
)
weatherInfoViewModel = WeatherInfoViewModel(
appPreferences = preferences,
connectivityObserver = connectivityObserver,
locationUseCases = locationUseCases,
weatherUseCases = weatherUseCase,
locationRepository = locationRepository,
)
}
@Test
fun firstTimeRunAppAndGrantLocationPermissionButLocationServiceDisabled_navigateToSearch() =
runTest {
// Arrange
locationRepository.isGpsEnabled = false
assertTrue(weatherInfoViewModel.isInitializing.value)
weatherInfoViewModel.onFirstTimeLocationPermissionResult(true)
runCurrent()
assertEquals(
WeatherDestinations.SEARCH_ROUTE,
weatherInfoViewModel.appRoute,
)
assertFalse(weatherInfoViewModel.isInitializing.value)
}
1条答案
按热度按时间rbpvctlc1#
是调试问题;尝试在FakeRepository中创建
isGpsEnabled = false
,并重新检查您的调试断点,如果它仍然为true,则意味着其他东西正在更改此值,因此请检查其他可能访问此值的位置并更改。其他可能的问题:
locationRepository
示例与WeatherInfoViewModel
使用的示例相同。创建对象的多个副本时,对一个副本的修改可能不会出现在其他副本中。如果这些解决方案都不起作用,请与我们分享源代码,以便我们可以在我们的终端调试它🙏!