Сбой Robolectric при попытке запустить gradlew test
или gradlew testDebugUnitTest
с этой ошибкой
> Task :app:testDebugUnitTest
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.robolectric.util.ReflectionHelpers$7 (file:/C:/Users/a.yasser/.gradle/caches/modules-2/files-2.1/org.robolectric/shadowapi/3.8/d638f001e81ef737bb35db2964312360cc996a94/shadowapi-3.8.jar)
to method java.lang.ClassLoader.getPackage(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.robolectric.util.ReflectionHelpers$7
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
ash.gaseelydriver.ui.activities.MainActivityTest > shouldNotBeNull FAILED
java.lang.NoClassDefFoundError
Caused by: java.lang.ClassNotFoundException
Caused by: java.lang.RuntimeException
Caused by: java.lang.IllegalArgumentException
эта проблема возникает, только если я запускаю из командной строки, я пробовал несколько решений, но ни одно из них не работало, включая
- удалить файл .gradle
- удалить .idea \ library
- удалить чистый / перестроить проект
- понижение и модернизация версий робоэлектрика
- обновление всей моей версии проекта компиляции и Taget SDK до 28
- перевод Gradle до версии от 3.1.2 до 3.2.0
вот файл gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ash.gaseelydriver"
minSdkVersion 17
targetSdkVersion 28
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file('ASH_Mobile.jks')
storePassword "Ahmedsh125"
keyAlias "ash_mobile"
keyPassword "Ahmedsh125"
}
}
buildTypes {
release {
zipAlignEnabled true
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
buildToolsVersion '28.0.2'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.intuit.sdp:sdp-android:1.0.4'
implementation 'com.intuit.ssp:ssp-android:1.0.5'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
testImplementation "org.robolectric:robolectric:3.8"
testImplementation 'org.mockito:mockito-core:2.7.22'
androidTestImplementation 'org.mockito:mockito-android:2.7.22'
implementation 'com.google.firebase:firebase-database:16.0.3'
implementation 'com.google.firebase:firebase-core:16.0.4'
testImplementation 'com.openpojo:openpojo:0.8.10'
}
apply plugin: 'com.google.gms.google-services'
вот пример тестового класса
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 27)
public class MainActivityTest {
private MainActivity activity;
@Before
public void setUp() {
activity = Robolectric.buildActivity(MainActivity.class).create()
.resume()
.get();
}
@Test
public void shouldNotBeNull() throws Exception {
assertNotNull(activity);
}