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:
And this one is from Run/Debug Configurations
where the JUnit
tests are under the unknown category:
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:
com.android.tools.build:gradle:7.0.0-beta02
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32
com.google.firebase:firebase-crashlytics-gradle:2.6.1
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)?
Android Studio - Arctic Fox | 2020.3. 1 Patch 4 is now available in the Stable channel. If you already have an Android Studio build on the Stable channel, you can get the update by clicking Help > Check for Update (Android Studio > Check for Updates on macOS). Otherwise, you can download it here.
To run all tests in a class or a specific method, open the test file in the Code Editor and do either of the following: Press the Run test icon in the gutter. Right-click on the test class or method and click Run . Select the test class or method and use shortcut Control+Shift+R .
Unit tests or small tests only verify a very small portion of the app, such as a method or class. End-to-end tests or big tests verify larger parts of the app at the same time, such as a whole screen or user flow. Medium tests are in between and check the integration between two or more units.
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'
This might not be the solution for everyone but our project had many unit tests that are broken due to Android Studio Arctic Fox's Gradle test runner. It appears that if you update to the latest Gradle plugin, right clicking on a test class will prompt a new Gradle "Create test" option..
We have not updated the plugin yet so our solution was to make our own Gradle Run Configuration for Unit tests.
This can be done by:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With