I am doing the Kotlin beginner course in Android Studio – and at the testing phase, Test results are always 0/0. How can I complete these tests?
Code is made by Google Android developers and it should work flawlessly. ( I used the same). App compiles without errors. The code is here:
https://github.com/google-developer-training/android-basics-kotlin-words-app
I tried all sorts of solutions:
- Espresso tests not running on Android 12
- Android instrumented test no tests found
- Upgraded gradle and everything to the latest versions.
- Tried it on Pixel 2 and Pixel 3 emulators
It may have something to do with either the Android Studio Version- Bumblebee or some settings made in the emulator to block testing. I suspect this, because when creating a previous app, at the testing phase the same thing happened (test results 0/0)
Test results says:
05/04 21:06:18: Launching ‘navigate_to_words_…()’ on Pixel 3 API 29.
App restart successful without requiring a re-install.
Running tests
$ adb shell am instrument -w -m -e debug false -e class ‘com.example.wordsapp.NavigationTests#navigate_to_words_nav_component’ com.example.wordsapp.test/android.support.test.runner.AndroidJUnitRunner
Connected to process 10870 on device ‘Pixel_3_API_29 [emulator-5556]’.>
What are your thoughts on this? Thank you for your time!
3
Answers
Just see the original
build.gradle
– you’re using the wrong test runner:In my case tests worked, but haven’t started today. I tried:
Then I launched the application and learnt that it didn’t start (crashed during start). In Logcat I saw an error and tried to resolve it. In my case it was Didn't find class "androidx.core.app.CoreComponentFactory", but a solution was https://stackoverflow.com/a/74836005/2914140:
in
gradle.properties
.After that I found that a problem was a bad dependency injection. I fixed it and reverted back
gradle.properties
.I’ve tried everything listed above but nothing worked.
What helped in my case is taking a look into Logcat, where was
android.os.NetworkOnMainThreadException
reported. Then I realized that I initializeMockWebServer
in myTestApplication
but I forget to add following call into myTestRunner
So it might be helpful to check Logcat as well:)