gpt4 book ai didi

android - 如何在 Robolectric 2.2 中指定自定义/res 目录?

转载 作者:行者123 更新时间:2023-11-29 00:23:31 34 4
gpt4 key购买 nike

我的单元测试和我的 Android 应用程序位于不同的项目中。

使用 Robolectric 1,我可以像这样指定我的/res 目录位置:

public class MyTestRunner extends RobolectricTestRunner {
public MyTestRunner(Class<?> testClass) throws InitializationError {
super(testClass, "../app/AndroidManifest.xml", "../app/res");
}
}

如何在 Robolectric 2.2 中指定/res 目录位置?

最佳答案

使用RobolectricTestRunner#getAppManifest(Config) :

public MyTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
}

@Override
protected AndroidManifest getAppManifest(Config config) {
return new AndroidManifest(
Fs.fileFromPath("../app/AndroidManifest.xml"),
Fs.fileFromPath("../app/res"),
Fs.fileFromPath("../app/assets"));
}

关于android - 如何在 Robolectric 2.2 中指定自定义/res 目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21464384/

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