Robolectric test hangs up when started - Transferring from sonatype
Asked Answered
P

4

8

I have a problem with configuring Robolectric in my project. I am also using Kotlin, if it matters.

Here is my build.gradle

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 26


testOptions {
    unitTests {
        includeAndroidResources = true
    }
}
sourceSets {
    test.java.srcDirs += ['build/generated/source/apt/test/debug']
}

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

ext.daggerVersion = '2.11'
ext.roomVersion = '1.0.0-alpha9'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'

kaptTest "com.google.dagger:dagger-compiler:$daggerVersion"
testImplementation 'junit:junit:4.12'
testImplementation "org.robolectric:robolectric:3.4.2"
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.1.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

// Room
implementation "android.arch.persistence.room:runtime:$roomVersion"
implementation "android.arch.persistence.room:rxjava2:$roomVersion"
kapt "android.arch.persistence.room:compiler:$roomVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.51"
androidTestImplementation "android.arch.persistence.room:testing:$roomVersion"

//DAGGER
implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"

//Jackson
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.1'

}

repositories {
mavenCentral()

}

When i run the test, it hangs up and on the console appears message:

Downloading: org/robolectric/android-all/o-preview-4-robolectric-0/android-all-o-preview-4-robolectric-0.jar from repository sonatype at https://oss.sonatype.org/content/groups/public/ Transferring 68498K from sonatype

I was waiting for about 10-15 minutes and still nothing.

Pincers answered 16/10, 2017 at 7:34 Comment(0)
P
5

I was waiting 30 minutes till it was downloaded. I also tried this on version 3.0 - was the same issue, but downloaded slightly faster.

I made an issue here: https://github.com/robolectric/robolectric/issues/3452

Maybe there is a way to improve speed download or something.

Pincers answered 16/10, 2017 at 10:28 Comment(2)
I'm running into the same problem, but why is this the accepted answer since it doesn't provide an official solution?Grandioso
I think the solution is just waiting, the download speed is terribly slow for some reasonMatrices
A
1

Inspired by K.Os, I found a way to specific the maven repository from Robolectric doc(http://robolectric.org/configuring/).

By setup the proxy or mirror maven repo, and change the systemProperty. It takes less time accessing the library from internal network.

    android {
      testOptions {
        unitTests.all {
          systemProperty 'robolectric.dependency.repo.url', 'https://local-mirror/repo'
          systemProperty 'robolectric.dependency.repo.id', 'local'
        }
      }
    }

It works for me, for CI pipeline task is always running on the machine, where the internet access is limited for security policy. It may leads to a stuck when Robolectric try to download its dependencies from default maven url.

I've submitted the same answer to https://github.com/robolectric/robolectric/issues/3452, too.

Alpinist answered 27/2, 2021 at 10:28 Comment(0)
C
0

Adding this into build.gradle solved the problem for me:

android{
    ...

    // Add these lines
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}
Christoperchristoph answered 23/11, 2019 at 16:41 Comment(0)
D
0

Potentially it's a network latency/connection issues depends on country or other network issues. Had the same problem and network monitor shows ~200kbs network download activity.

After enabling VPN it shows ~100Mbs network activity and takes several seconds to download from sonatype.

Dismuke answered 10/3, 2020 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.