私のプロジェクトにインストゥルメントテストを実行しようとしています。しかし、バージョン5(API 21)未満のデバイス(エミュレータ)では動作しません。5(API 21)以下のデバイスでAndroidテストが実行されないNoClassDefFoundError
私はこの問題を解決しようとしていますが、まだそれに直面しています。 次の例外が発生します。
02-15 10:46:08.965 1127-1143/? E/AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner
java.lang.ExceptionInInitializerError
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:81)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:524)
at android.support.test.runner.AndroidJUnitRunner.createTestRequestBuilder(AndroidJUnitRunner.java:379)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:352)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:269)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
Caused by: java.lang.NoClassDefFoundError: org.junit.runner.manipulation.Filter$1
at org.junit.runner.manipulation.Filter.<clinit>(Filter.java:21)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:81)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:524)
at android.support.test.runner.AndroidJUnitRunner.createTestRequestBuilder(AndroidJUnitRunner.java:379)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:352)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:269)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
私はすでに同様の質問に対してすべてのソリューションを試しました。
ここで私のプロジェクト構造はどのように見えますか?
そしてGradleのテスト
/************* TEST STUFF ***************/
androidTestCompile 'junit:junit:4.12'
androidTestCompile fileTree(include: ['robotium-solo-5.5.2.jar'], dir: 'libs')
//mockito dependencies
androidTestCompile 'org.mockito:mockito-core:2.7.6'
androidTestCompile files('libs/dexmaker-mockito-1.0.jar')
androidTestCompile files('libs/dexmaker-1.0.jar')
// Set this dependency to build and run Espresso tests
androidTestCompile('com.android.support.test.espresso:espresso-core:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to use JUnit 4 rules
androidTestCompile('com.android.support.test:rules:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
//MockWebServer - Version 2.2 of mockwebserver doesn't work because of an issue, so forcing v2.1 - https://github.com/square/okhttp/issues/1069
androidTestCompile('com.squareup.okhttp3:mockwebserver:+') {
exclude module: 'okhttp'
}
androidTestCompile "org.slf4j:slf4j-api:1.7.12"
//WireMock
androidTestCompile("com.github.tomakehurst:wiremock:2.5.0") {
//Using Android Version Instead
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
//Version conflict with our app's slf4j version
exclude group: 'org.slf4j', module: 'slf4j-api'
//Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
exclude group: 'org.ow2.asm', module: 'asm'
//Was getting this warning, so decided to ignore this version included by WireMock.
//Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
//In case of problem, please repackage with jarjar to change the class packages
exclude group: 'org.json', module: 'json'
}
androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
そしてBaseTestClass
の依存関係は、次のような構造
@RunWith(AndroidJUnit4.class)
public abstract class InstrumentalSuperTest {
private SystemAnimations mSystemAnimations;
@Rule
public IntentsTestRule rule = provideActivity();
@Rule
public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.wireMockConfig().port(BuildConfig.PORT), false);
protected abstract IntentsTestRule provideActivity();
}
を持っており、これは私のプロジェクトではなく、同様Wiremock examplesていないだけで起こります、同じエラー。
多分私はテストを間違って実行します。私はテストクラスをクリックしてRun ... Test
を選択します。
この問題を解決するにはどうすればよいですか、何が間違っているかわかりません。
'provideActivity()'はカスタムメソッドですか?あなたはそれの内容を提供できますか? – sebokopter
は、重複の可能性:https://stackoverflow.com/questions/40867407/android-espresso-multidex-failを multiDexKeepProguardファイル( '../ proguardRules/multidex-proguard.pro') 中を定義してみてくださいあなたのフレーバーの設定とファイル内でプログアードのような構文を使ってテストで見つけられないクラスを保つことができますmultidexは時々正しくテストするために悪魔です – originx
Lollipopの前にテスト用のAPKをマルチデックスできないやってみてください。 WireMockには膨大なメソッドカウントフットプリントしかありません。私の推測では、あなたのテストAPKはマルチエクステンションであると思います。最初のdexファイルは取得されますが、それ以降のdexファイルのものは使用できなくなり、他のdexファイルのクラスにアクセスしようとするとClassNotFoundExceptionが発生します。 –