skip to Main Content

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:

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


  1. Just see the original build.gradle – you’re using the wrong test runner:

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    
    Login or Signup to reply.
  2. In my case tests worked, but haven’t started today. I tried:

    • invalidate caches and restart,
    • edit configuration,
    • change settings (Java version, etc.),
    • sync project with Gradle files,
    • checkout old commits and try to build from there,
    • restore default IDE settings,
    • wipe emulators,
    • build an application.

    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:

    android.useAndroidX=true
    android.enableJetifier=true
    

    in gradle.properties.

    After that I found that a problem was a bad dependency injection. I fixed it and reverted back gradle.properties.

    Login or Signup to reply.
  3. 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 initialize MockWebServer in my TestApplication but I forget to add following call into my TestRunner

    StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build())
    

    So it might be helpful to check Logcat as well:)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search