google-developer-training / android-basics-kotlin-cupcake-app

Apache License 2.0
103 stars 163 forks source link

Cannot resolve symbol InstantTaskExecutorRule #61

Closed mcavoya closed 8 months ago

mcavoya commented 2 years ago

URL of codelab https://developer.android.com/codelabs/android-basics-kotlin-test-viewmodel-and-livedata#4

In which task and step of the codelab can this issue be found? Task: Test ViewModels and LiveData Step 5: Add the necessary dependencies

Describe the problem Codelab is using the wrong dependency. The problem becomes apparent in step 6, when you try to add @get:Rule var instantTaskExecutorRule = InstantTaskExecutorRule()

Which generates the error, "Cannot resolve symbol InstantTaskExecutorRule"

Use androidTestImplementation to fix the problem.

Steps to reproduce? Follow the codelab. See the error in step 6.

Versions Android Studio Bumblebee | 2021.1.1 Patch 2 Build #AI-211.7628.21.2111.8193401, built on February 17, 2022 Runtime version: 11.0.11+9-b60-7590822 amd64 VM: OpenJDK 64-Bit Server VM by Oracle Corporation Windows 10 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 1280M Cores: 8 Registry: external.system.auto.import.disabled=true Non-Bundled Plugins: org.jetbrains.kotlin (211-1.6.20-release-275-AS7442.40)

Additional information Please refer to the accepted StackOverflow answer. https://stackoverflow.com/questions/48049131/cannot-resolve-symbol-instanttaskexecutorrule

adrian-best commented 1 year ago

To be specific, the dependencies in step 5 should be: androidTestImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.arch.core:core-testing:2.1.0'

Not just 'testImplementation'