gpt4 book ai didi

java - 生成的 Android espresso 测试运行失败,AndroidJUnitRunner 解析失败 : Landroidx/test/platform/io/FileTestStorage;

转载 作者:行者123 更新时间:2023-12-05 00:02:32 26 4
gpt4 key购买 nike

在我的应用程序上录制了一个简单的 Espresso 测试后,测试无法运行,我希望有人能指导我了解为什么会发生这种情况。产生的错误是:

D/AndroidJUnitRunner: Use the raw file system for managing file I/O.
E/AndroidRuntime: FATAL EXCEPTION: Instr: androidx.test.runner.AndroidJUnitRunner
Process: com.companyname.appname, PID: 2343
**java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/platform/io/FileTestStorage;**
at androidx.test.runner.AndroidJUnitRunner.registerTestStorage(AndroidJUnitRunner.java:671)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:447)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2152)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.test.platform.io.FileTestStorage" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.companyname.appname.test-IqFAu-mtwBYt8la6Xi2kdA==/base.apk", zip file "/data/app/com.companyname.appname-mWOZlXK4F0npIJ34j66euw==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.appname.test-IqFAu-mtwBYt8la6Xi2kdA==/lib/arm, /data/app/com.companyname.appname-mWOZlXK4F0npIJ34j66euw==/lib/arm, /system/lib, /system/product/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at androidx.test.runner.AndroidJUnitRunner.registerTestStorage(AndroidJUnitRunner.java:671) 
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:447) 
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2152) 
I/Process: Sending signal. PID: 2343 SIG: 9
Disconnected from the target VM, address: 'localhost:53625', transport: 'socket'
我正在使用的 Build.gradle 看起来像:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 29
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.companyname.appname"
minSdkVersion 16
targetSdkVersion 29
versionCode 4
versionName "1.3.0"
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
signingConfig getSigningConfig()
applicationVariants.all { variant ->
variant.outputs.each { output ->
variant.outputs.all {
outputFileName = "AppName_${variant.versionName}.apk"
}
}
}
}
debug {
debuggable true
minifyEnabled false
}
}
packagingOptions {
// exclude 'META-INF/services/javax.annotation.processing.Processor'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
// abortOnError false
}
dexOptions {
preDexLibraries false
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.android.gms:play-services:8.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.versionedparcelable:versionedparcelable:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.test.ext:junit:1.1.3'

androidTestImplementation 'androidx.test:runner:1.4.1-alpha01'
androidTestImplementation 'androidx.test:rules:1.4.1-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha01'
}
Espresso java 文件(有一些我试过的注释掉的东西):
package com.companyname.appname;

import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.DataInteraction;
import androidx.test.espresso.ViewInteraction;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.filters.LargeTest;
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.pressBack;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.action.ViewActions.*;
import static androidx.test.espresso.assertion.ViewAssertions.*;
import static androidx.test.espresso.matcher.ViewMatchers.*;

import com.companyname.appname.R;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;

@LargeTest
@RunWith(AndroidJUnit4.class) //AndroidJUnit4ClassRunner.class
public class MainActivityTestPortrait2
{

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
// public ActivityScenarioRule<MainActivity> activityRule =
// new ActivityScenarioRule<>(MainActivity.class);

@Test
public void mainActivityTestPortrait2()
{
// ActivityScenario scenario = activityRule.getScenario();

ViewInteraction relativeLayout = onView(
allOf(withId(R.id.menuButton),
childAtPosition(
childAtPosition(
withClassName(is("com.android.internal.widget.ActionBarView")),
1),
2),
isDisplayed()));
relativeLayout.perform(click());

ViewInteraction relativeLayout2 = onView(
allOf(withId(R.id.menuButton),
childAtPosition(
childAtPosition(
withClassName(is("com.android.internal.widget.ActionBarView")),
1),
2),
isDisplayed()));
relativeLayout2.perform(click());

ViewInteraction relativeLayout3 = onView(
allOf(withId(R.id.menuButton),
childAtPosition(
childAtPosition(
withClassName(is("com.android.internal.widget.ActionBarView")),
1),
2),
isDisplayed()));
relativeLayout3.perform(click());
}

private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position)
{

return new TypeSafeMatcher<View>()
{
@Override
public void describeTo(Description description)
{
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}

@Override
public boolean matchesSafely(View view)
{
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}

最佳答案

意识到我有一个依赖项( implementation 'androidx.test.ext:junit:1.1.3' ),它破坏了构建 AndroidJUnitRunner.java。删除此行允许测试运行 - 不成功,但这是另一个问题。

关于java - 生成的 Android espresso 测试运行失败,AndroidJUnitRunner 解析失败 : Landroidx/test/platform/io/FileTestStorage;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69307361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com