gpt4 book ai didi

android - Robolectric: “AndroidManifest.xml not found” 和 "Unable to find resource ID #0x7f09001b"

转载 作者:行者123 更新时间:2023-11-29 14:30:00 28 4
gpt4 key购买 nike

我正在使用 Roboletric 运行一些测试,但我遇到了一个我无法解决的问题。当我运行测试时,“AndroidManifest”出现以下错误:

WARNING: No manifest file found at .\AndroidManifest.xml.

Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE).

No such manifest file: .\AndroidManifest.xml

我已经尝试了这些失败的解决方案:

@Config (manifest = Config.DEFAULT_MANIFEST_NAME)

@Config(manifest = Config.NONE, constants = BuildConfig.class, sdk = 26)

@Config( constants = BuildConfig.class, manifest="src/main/AndroidManifest.xml", sdk = 26 )

执行过程中的另一个错误是:

android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f09001b in packages [android, org.robolectric.default]

...

at

com.example.robertoassad.alltestsmerge.MainActivity.onCreate(MainActivity.java:52)

这一行有错误的是下面的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

具体在:setContentView(R.layout.activity_main);

对我来说,我认为这个问题没有意义......

详情:

  • 测试类在文件夹中:app\src\test\java\com\example\robertoassad

  • 测试是:
    @RunWith(RobolectricTestRunner.class)
    公共(public)类 Roboletric {

    @测试
    public void clickingLogin_shouldStartLoginActivity() {
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    activity.findViewById(R.id.button2).performClick();

            Intent expectedIntent = new Intent(activity, SecondActivity.class);
    Intent actual = ShadowApplication.getInstance().getNextStartedActivity();
    assertEquals(expectedIntent.getComponent(), actual.getComponent());
    }

最佳答案

我遇到了和你遇到的问题类似的问题。 post by jongerrish在 Robolectric GitHub Issue 上关于这个的问题为我解决了这个问题。

对我有用的答案是在我模块的 build.gradle 文件中添加一个 testOptions block :

testOptions {
unitTests {
includeAndroidResources = true
}
}

添加此 block 后,我的测试能够运行并访问字符串资源。

关于android - Robolectric: “AndroidManifest.xml not found” 和 "Unable to find resource ID #0x7f09001b",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47456711/

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