Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
970 views
in Technique[技术] by (71.8m points)

Unit tests not working on Android Studio Arctic Fox

I've recently installed Android Studio Arctic Fox v2020.3.1 Beta 2 to be able to use Jetpack Compose in our project since I wasn't able to do so back on AS 4.2.1 because Compose was throwing a strange build error that got fixed on Arctic Fox.

So here's the problem, after loading the project, updating some SDKs/libraries I was able to build and run no problem, however, when I went to run the unit tests I noticed that all test classes were no longer recognized by the IDE. After some investigation I found out that newer versions of AS will no longer recognize JUnit configurations.

As you can see in the screenshots below there is no way to run those tests as I normally would:

enter image description here

enter image description here

And this one is from Run/Debug Configurations where the JUnit tests are under the unknown category:

enter image description here

Finally, I did create a gradle config to test but it just says on the left side:

Test events were not received

And throws an error on the right side:

Execution failed for task 'features:signup:testDevDebugUnitTest'. No tests found for given includes: com.projectsaturn.android.features:signup.SignupViewModelTest

I wonder if anyone out there has come across this issue and was able to resolve?

Any help is appreciated!

UPDATE 01:

So I decided to roll everything back and start from scratch. This time I only updated a few things:

  • Gradle: com.android.tools.build:gradle:7.0.0-beta02
  • Kotlin: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32
  • Crashlytics: com.google.firebase:firebase-crashlytics-gradle:2.6.1
  • Test (core, runner and rules): androidx.test:core/runner/rules:1.3.0

Now the issue is that all unit tests fail when I run it via Gradle. I suspect that it isn't running the @Before annotated function prior to running the actual tests functions. Or I'm not setting the Gradle test properly (screenshot below)?

enter image description here

question from:https://stackoverflow.com/questions/67713500/unit-tests-not-working-on-android-studio-arctic-fox

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're using Android Studio Arctic Fox, you need to modify your app/build.gradle a bit.

Add

android {
    testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'

        unitTests.all {
            useJUnitPlatform() // <--- this is the important part
        }
    }
}

And also make sure you add junit-engine to your dependencies

testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...