Describe the problem
When the ViewModel is initialised, this currentWord = allWords.random() method is called. allWords lies in WordsData.kt file. The test source set has different implementation of allWords. But how is it getting swapped automatically without any dependency injection? How does ViewModel automatically know that for testing it should use the test file?
When I renamed the file in test source set, the ViewModel was calling the method from main source set during testing. So it is due to the fact that method lies in same file structure? If so? Why bother for DI for swapping fakes such as a fake repository?
URL of codelab https://github.com/google-developer-training/basic-android-kotlin-compose-training-unscramble/blob/main/app/src/main/java/com/example/unscramble/ui/GameViewModel.kt
Describe the problem When the ViewModel is initialised, this
currentWord = allWords.random()
method is called.allWords
lies inWordsData.kt
file. The test source set has different implementation ofallWords
. But how is it getting swapped automatically without any dependency injection? How does ViewModel automatically know that for testing it should use the test file?When I renamed the file in test source set, the ViewModel was calling the method from main source set during testing. So it is due to the fact that method lies in same file structure? If so? Why bother for DI for swapping fakes such as a fake repository?