Hi i am using robolectric version 3.0 for unit testing my app and have the asssets folder with some files inside under src/test/assets but keep getting fileNotFound.
Here is my test code:
```
@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;
}
}
```
Here is my sourceset and dependencies from my gradle file: ```
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'
```
production is a build varient
Aucun commentaire:
Enregistrer un commentaire