I had been running my unit test so far without any problems until we decide to update the gradle version from 3.1 to 4.6 and the gradle plugging from 2.3.3 to 3.5. After this update the project run without any problem and even the unit tests runs fine but not the ones that need to import AndroidJUnit4 because it can't resolve the dependence any more.
On the build.gradle we are importing:
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
Any idea?
Thanks in advance
androidTestImplementation and the runner are used for UI tests. You seem to not be explicitly importing JUnit:
testImplementation "junit:junit:4.12"
Related
I tried to implement some unit and instrumented tests for my Android application (Java), my unit tests is working fine but instrumented tests are failing:
#RunWith(AndroidJUnit4.class)
#LargeTest
public class ExampleInstrumentedTest {
#Rule
public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class);
#Test
public void checkIfCategoriesIsNotEmpty() {
onView(withId(R.id.header_left_layout)).perform(click());
onView(withId(R.id.list_view)).check(new ViewAssertion() {
#Override
public void check(View view, NoMatchingViewException noViewFoundException) {
ListView list_categories = (ListView) view;
ListAdapter adapter = list_categories.getAdapter();
Assert.assertTrue(adapter.getCount() > 0);
}
});
}
}
When I try to run my test I got this error :
"Run Android instrumented tests using Gradle" option was ignored because this module type is not supported yet.
My Implementations in build.config file are :
// UNIT TEST
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
// INSTRUMENTED TEST
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
I just ran into this problem, too. I found the solution in the Android Studio Bumblebee 2021.1.1 release notes under the "Android testing" section.
It basically amounts to unchecking the box next to Run Android instrumented tests using Gradle in the testing settings. This worked for me.
the solution is to exclude module: protobuf-lite :
androidTestImplementation('androidx.test.espresso:espresso-contrib:3.4.0') {
exclude module: "protobuf-lite"
}
As mentioned here
Disable the unified Gradle test runner
By default Android Studio Bumblebee uses Gradle to run its instrumentation tests. If you're experiencing issues, you can disable this behavior as follows:
Select File > Settings > Build, Execution, Deployment > Testing (or Android Studio > Preferences > Build, Execution, Deployment > Testing on MacOS.)
Uncheck the box next to Run Android instrumented tests using Gradle and click OK.
So you can just disable the unified Gradle test runner.
For me, the issue was that I was running on Xiaomi Redmi note 7. Once I switched to the emulator. everything worked fine.
Pretty weird problem: Mockito deps look broken even though they actually work.
Why does this happen and how to fix it?
The tooltip over those errors says "unresolved reference".
Some details:
These are unit tests (under app/src/test), not Android instrumentation tests.
This only happens when the test is Kotlin. In equivalent Java test, Mockito deps show up just fine in Android Studio.
To reiterate, even though Mockito stuff is shown in red, it still works: the test compiles and passes, both on the command line and in Android Studio.
In build.gradle, under dependencies:
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.19.0'
// ...
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50"
(Also I have a file named org.mockito.plugins.MockMaker containing mock-maker-inline, so that Mockito works with final Kotlin classes.)
Edit: This shouldn't be relevant, but for Android instrumentation tests, there's also this. (I had some problems updating to Mockito 2 earlier, so sticking with 1.10.19 there.)
// Here keeping older Mockito for now
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
// dexmaker needed for Mockito to work in androidTest
androidTestImplementation 'com.google.dexmaker:dexmaker:1.2'
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
Using Android Studio 3.5.3
What I've tried
Re-sync the project (build.gradle)
Run clean Gradle task inside AS
Close the project and open it again
Quit Android Studio completely and open it again
Update
I think this is related to several versions of Mockito being present in the project.
When I Cmd-click on the names shown in red, it takes me to sources in mockito-core-1.9.5-sources.jar; but when I Cmd-click on ArgumentMatchers or MockitoJUnitRunner, it takes me to mockito-core-2.19.0-sources.jar, the correct one.
I investigated with app:dependencies, and the only reference to Mockito 1.9.5 is through dexmaker-mockito.
+--- com.google.dexmaker:dexmaker-mockito:1.2
| +--- com.google.dexmaker:dexmaker:1.2
| \--- org.mockito:mockito-core:1.9.5 -> 1.10.19 (*)
But as dexmaker dependency is only for androidTest it shouldn't affect anything under test, right...? š¤
Edit: indeed, the androidTest deps somehow confused Android Studio; commenting out all mockito and dexmaker deps in androidTestImplementation removed the faulty error highlights (but as mentioned, the different version was used for a reason).
In the end, Android Studio update fixed this.
Oh well, this was a bug in Android Studio: updating to latest version (3.6.2) fixed it.
The androidTestImplementation dependencies were conflicting with testImplementation ones; see updated question for details.
I have been working on sample UIAutomator project. I have created new Testcases using AndroidX Testing libraries.
I am able to build, run the test cases from the command line. But when I tried to open the app from Android Studio I can see most of the classes are not imported properly. For eg.,
import androidx.test.uiautomator.UiObject2;
import org.junit.Before;
The above two imports are showing as not imported. Likewise lots of classes are showing the same error except android.content.Context, android.content.Intent, etc.,
Can someone through some light on this. I am able to execute the testcases properly from the command line but not able to execute them properly from Android Studio.
I have Restarted PC/Studio, cleared caches, still the problem exists.
below is the dependency I have added in app/build.gradle.
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test:core:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'junit:junit:4.12'
Added the below code in gradle.properties
android.useAndroidX=true
android.enableJetifier=true
I have pretty much followed the same what I have got from android-testing-master/ui/uiautomator sample code, not sure what I am missing.
I faced same problem too (Android Studio 3.4.2), uiautomator was red:
import androidx.test.uiautomator.UiDevice
"Clean Project" and "Rebuild Project" didn't help, even invalidating caches. But choosing another Build Variant helped me.
I have written instrumentation tests which was working fine, but now getting error cannot resolve ActivityTestRule error after upgrading dependencies to
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
I am using android support version 27.1.1
It is working fine with dependencies
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
In the most recent update of the Testing Support Library (2018-04-24), the "rules" dependency was apparently removed from the espresso-core. I'm not sure why this was done, but the release notes say this about the change:
Fixed espresso-core POM file to not pull in "rules" dependency, instead have espresso-intents POM pull it. This should be a NoOp change for developers since espresso-intents cannot be used without espresso-core.
You can fix this problem by adding the following dependency to app/build.gradle:
androidTestImplementation 'com.android.support.test:rules:1.0.2'
AndroidX Test includes another API,ActivityScenario that is currently in beta. This API works in a variety of testing environments and provides thread safety within the tests that use it. Consider using ActivityScenarioRule or ActivityScenario instead.
import androidx.test.ext.junit.rules.ActivityScenarioRule
ActivityScenarioRule(YourActivity::class.java)
Big problem since upgrading to Android Studio 3.1, I get:
No cached version of com.github.bumptech.glide:compiler:4.6.1 available for offline mode
But I am not in offline mode as you can see here:
I tried Clean Project and Rebuild Project, all with no success.
I even rebooted my PC.
Here's my Build.gradle:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation "com.android.support:gridlayout-v7:27.1.0"
implementation 'com.android.support:exifinterface:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.code.gson:gson:2.8.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}
I ran into this issue and "offline work" was unchecked inside gradle settings. After wasting 2 hours on it, I realized that I had --offline in the Command-line options of Build, Execution, Deployment > Compiler. So make sure you don't have that command listed there when you encounter this issue.
You should close Gradle offline-work model and clear compiler Command-line Options --offline:
The only thing that worked for me was to remove the "--offline" in "File -> Settings -> Compiler -> Command-line Options".
I don't know why this parameter was there but anyway...now it's ok.
Dont know what was going on, maybe it was really due to JCenter being partly down during the day. Probably because half the globe was upgrading Android Studio to 3.1.
I cleaned the cache (70.000 files!), no effect, except from a resulting hourlong download of thousands of files, mainly from JCenter, with at least 10 fails (time outs?) along the way.
End result: Gradle still complaing about
No cached version of com.github.bumptech.glide:compiler:4.6.1 available for offline mode
Then in desparation, I modified
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
to
`compile group: 'com.github.bumptech.glide', name: 'compiler', version:` '4.6.1'
in my Build.gradle.
The result was of course an error message.
After then changing back to where I came from
compile group: 'com.github.bumptech.glide', name: 'compiler', version: '4.6.1'
Bingo: all was good, no idea why.
Thanks for your help anyway
First My English is very poor,Sorry.
I meet this problem tooļ¼when I upgrade my AndroidStudio to 3.1 and update gradle 3.0.1 to 3.1.0 ļ¼then I build to run my projectļ¼it is error āno version of butterknife in offline modeāļ¼but I'm sure itās not offline modećI have tried to a lot of ways ,doesn't work.
Then I try to add dependences in AndroidStudio ProjectStructure--app--dependences,search and selected the butterknife,and then build to run.
It works!
https://blog.csdn.net/binglumeng/article/details/79747651
I hope It can help you!
have you tried invalidating your cache and restarting your android studio?
or else if your working behind a proxy network checkout this
link