Robolectric filenotFound在资产文件上

时间:2015-09-29 15:20:45

标签: android unit-testing gradle robolectric robolectric-gradle-plugin

您好我正在使用robolectric版本3.0对我的应用进行单元测试,并且在src / test / assets下有一些文件,其中包含一些文件但仍然获取fileNotFound。

这是我的测试代码:

```

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, manifest = Config.NONE)
public class ShowsDatesTest {

@Test
public void testResponse(){
BufferedReader = getBufferedResponseFromFile("response.json");
}

private BufferedReader getBufferedResponseFromFile(String json) throws IOException {

         mContext = RuntimeEnvironment.application;
        InputStream jsonResponse = mContext.getAssets().open(json);

        BufferedReader br = new BufferedReader(new InputStreamReader(jsonResponse, "UTF-8"));

        return br;

    }

}

```

这是我的gradle文件中的源集和依赖项: ```

 production {
            res.srcDir 'build-config/production/res'
            test.java.srcDirs += 'src/main/java'
            test.java.srcDirs += "build/generated/source/r/production"
            test.java.srcDirs += "build/generated/source/buildConfig/production"
            test.assets.srcDir file('src/test/assets')
        }

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.1.+'
    compile 'com.google.code.gson:gson:2.3'
    testCompile('org.robolectric:robolectric:3.0') {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    compile 'com.fasterxml.jackson:jackson-parent:2.5'
    compile 'com.squareup:otto:1.3.6'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.sothree.slidinguppanel:library:3.0.0'
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'joda-time:joda-time:2.8.2'
    testCompile('junit:junit:4.12') {
        exclude module: 'hamcrest'
        exclude module: 'hamcrest-core'
    }
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    compile 'com.sothree.slidinguppanel:library:3.0.0'
    compile 'com.squareup:otto:1.3.6'
    compile 'com.squareup.okhttp:okhttp:2.3.0'
    testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'

    compile 'com.google.android.gms:play-services:7.0.0'

    compile 'com.android.support:multidex:1.0.0'

    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'com.squareup.picasso:picasso:2.5.2'

```

生产是构建变量

0 个答案:

没有答案