Gradle Build Timeout for a Fragment Test - android

For some reason the status says Gradle build Running infinitely or it just times out.
#RunWith(AndroidJUnit4ClassRunner::class)
class UserTest {
#Test
fun test_isMovie() {
val scenario = launchFragmentInContainer<UserList>()
}
}
I do have another Instrumentation based Test class which runs fine, it's the individual Fragment test class that I'm having problems with.
The dependencies for build.gradle (app) looks like this. Please advise.
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.1'
debugImplementation "androidx.fragment:fragment-testing:1.5.5"
androidTestImplementation "org.hamcrest:hamcrest:2.2"
androidTestImplementation 'androidx.test:rules:1.5.0'
build.gradle (app) looks like this
android {
namespace 'com.demo.example'
compileSdk 33
defaultConfig {
applicationId "com.demo.example"
minSdk 33
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} ...

Related

RecyclerView, LiveData, Lifecycle dependencies

Hello kind people of the internet.
My name is Paul.
I've started to learn Android development using Kotlin, lately I've been following a couple of tutorials regarding RecyclerView, LiveData and Lifecycle.
At first I honestly forgot to declare the dependencies inside my gradle script.
But I have discovered that the functionality actually works as expected.
Can somebody please explain to me this phenomenon:
is it because Android Studio "saw" my imports and automatically "defined" and downloaded the dependencies ?
is it because of the compileSdk version?
Here is a sample of my dependencies block from one of my projects
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Also here is my config
defaultConfig {
applicationId "com.example.myrecycler"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Thank you!

Class not found. Test class not found

Here is it my sreen:
What settings should I set?
How to avoid deprecated class?
I would like to use espresso, after that try to use UiAutomator, how to set needed necessary settings?
I lost almost whole day.
#RunWith(AndroidJUnit4::class)
#LargeTest
class MainActivityTest {
#Rule
#JvmField
var activityTest = ActivityTestRule(MainActivity::class.java)
fun c(){
assertEquals(1,1)
}
}
GRADLE
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.network"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
//okhttp library
implementation("com.squareup.okhttp3:okhttp:4.7.2")
// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
//gson
implementation 'com.google.code.gson:gson:2.8.6'
//recycler
implementation "androidx.recyclerview:recyclerview:1.1.0"
//picasso
implementation 'com.squareup.picasso:picasso:2.71828'
//broadcast
implementation 'com.android.support:design:26.1.0'
//interceptor
implementation 'com.squareup.okhttp3:logging-interceptor:3.7.0'
}
You've not set the test runner correctly.
This line:
"android.support.test.runner.AndroidJUnitRunner"
should be instead:
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
as you are using the new androidx libraries instead of the old support ones.
Without this you'll get this No tests were found errors. Don't forget to add the testInstrumentationRunner keyword.
And add junit to androidTestImplementation also in de gradle file:
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

Unresolved reference : ActivityScenario

I was just learning how to create tests using Robolectric. I was just writing my first Test as following:
#RunWith(RobolectricTestRunner::class)
class MainActivityTest {
lateinit var mainActivity: MainActivity
#Before
fun setUp() {
mainActivity = setupActivity(MainActivity::class.java)
}
}
But here it shows that setupActivity is deprecated and i should use something called ActivityScenario. So i tried adding dependencies for it as following:
Module level build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.unittesting"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.3.1'
// Core library
androidTestImplementation 'androidx.test:core:1.2.0'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:truth:1.2.0'
androidTestImplementation 'com.google.truth:truth:0.42'
// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.2.0'
// The following Espresso dependency can be either "implementation"
// or "androidTestImplementation", depending on whether you want the
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'
}
Still i am unable to resolve the class ActivityScenario. I don't know what i am missing.

What is error package android x and Android J Unit 4?

I wrote a sample code and received these errors.
error: cannot find symbol class Android J Unit 4.
and
error: package android x test ext j unit runners does not exist
I installed the latest version of android studio and after running each code I received these errors.
What do the errors mean?
Code:
package com.example.hello;
public class JavaBasics {
public static void main(String args[]){
System.out.println("Hello World");
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.hello"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
I solve it..
i must use
#RunWith(AndroidJUnit4.class)
in . java and
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
in app (build.grade)

Android Studio "unused import" message when putting SDK inside build.gradle

I'm trying to insert an SDK called Mesibo for communication, and in my project it instantly greys out when I try to import: import com.mesibo.api.mesibo; with the message cannot resolve symbol 'mesibo' and unused import around it
This is the build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.richard.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.mesibo.api:mesibo:1.0.5'
implementation 'com.mesibo.api:calls:1.0.3'
implementation 'com.mesibo.api:ui:1.0.4'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
import com.mesibo.api.mesibo;
I'm following their documentation, and the import stops gradle from syncing with the project for some reason. I'm very new to Android Studio and this is my first time attempting to place an SDK + API in.
This goes in your Java/Kotlin code, not in Gradle
import com.mesibo.api.mesibo;
So remove it from there, and then compile the code, then add it to the other source files you need this class.
And I think that their documentation is very poor... should be
import com.mesibo.api.Mesibo;
https://github.com/mesibo/samples/tree/master/android/MesiboSample/app/src/main/java/com/mesibo/firstsample

Categories

Resources