gpt4 book ai didi

Android FragmentScenario - 找不到包 androidx.fragment.app.testing

转载 作者:行者123 更新时间:2023-12-04 23:50:57 28 4
gpt4 key购买 nike

尝试在 Android 中使用 FragmentScenario 时出现此错误

error: package androidx.fragment.app.testing does not exist
import androidx.fragment.app.testing.FragmentScenario;
^

这是我的简单单元测试示例:
package com.example.myapplication;

import androidx.fragment.app.testing.FragmentScenario;
import android.os.Build;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;

@RunWith(AndroidJUnit4.class)
@Config(manifest = Config.NONE, sdk = Build.VERSION_CODES.P)
public class MainActivityTest {
@Test
public void testFragmentScenario() {
FragmentScenario<BlankFragment> scenario = FragmentScenario.launchInContainer(BlankFragment.class);
}
}

构建.gradle(应用程序):
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

def test_version = '1.2.0'
def fragment_version = '1.2.4'
debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
testImplementation "androidx.test:core:$test_version"
testImplementation 'androidx.test.ext:junit:1.1.1'
testImplementation "androidx.test:runner:$test_version"
testImplementation "androidx.test:rules:$test_version"
testImplementation 'org.robolectric:robolectric:4.3'
}

我错过了什么,因为几个月前这段代码有效。

最佳答案

看来你用错了方法,试试改debugImplementationtestImplementationbuild.gradle .希望对您有所帮助。

关于Android FragmentScenario - 找不到包 androidx.fragment.app.testing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61083072/

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