5

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 Answers3

1

Just see the original build.gradle - you're using the wrong test runner:

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • I'm sure this is a correct answer for many, it didn't solve my issues unfortunately. I did however discover while using Kaspresso, adding in the shell command in the Kaspresso builder used in the TestCase constructor caused the issue for me. I'll reward bounty anyway as I'm sure others find this answer useful. Thanks! – quaternion Jul 03 '22 at 22:44
  • 5
    doesn't work for me, still see 0/0 – Alexander Tumanin Sep 05 '22 at 16:52
0

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.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
0

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:)

the korovay
  • 563
  • 4
  • 16