Using multiple res folders with Robolectric

后端 未结 2 1694
滥情空心
滥情空心 2020-12-07 05:48

My current Gradle configuration has multiple (Merged) res folders:

sourceSets {
    androidTest {
        setRoot(\'src/test\')
    }
    main {
        res.         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 06:01

    Another solution similar to Luca's:

    public class MyTestRunner extends RobolectricTestRunner {
        ...
        @Override
        protected AndroidManifest getAppManifest(Config config) {
            String appRoot = "./src/main/";
            String manifestPath = appRoot + "AndroidManifest.xml";
            String resDir = appRoot + "res";
            String assetsDir = appRoot + "assets";
    
            return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) {
                @Override
                public List getIncludedResourcePaths() {
                    List paths = super.getIncludedResourcePaths();
                    paths.add(new ResourcePath(getRClass(), getPackageName(), Fs.fileFromPath("../app/src/main/res/features/registration"), getAssetsDirectory()));
                    paths.add(new ResourcePath(getRClass(), getPackageName(), Fs.fileFromPath("../app/src/main/res/features/login"), getAssetsDirectory()));
                    return paths;
                }
            };
        }
    }
    

    Don't forget to annotate your tests with @RunWith(MyTestRunner.class)

提交回复
热议问题