Robolectric: androidTest assets not picked up

Created on 6 Jun 2018  路  3Comments  路  Source: robolectric/robolectric

Description

I use Room and try to test my db locally using robolectric.
In room you can specify the schema export by

  sourceSets {
    androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
  }

However these assets are not picked up by robolectric and the android.arch.persistence.room.testing.MigrationTestHelper fails because it does not find the schema in the assets.

Robolectric & Android Version

4.0.0-alpha2
Android 27

Most helpful comment

I found a workaround.

Using test.assets.srcDirs did not work, but adding them to debug.assets.srcDirs worked.

All 3 comments

I found a workaround.

Using test.assets.srcDirs did not work, but adding them to debug.assets.srcDirs worked.

I'm going to close this. Android Studio now has first class support for Robolectric (merges and compiles resources in your deps). I don't think it supports assets in the tests folder however but if you'd like that please open an issue on the google tracker for Android Studio

If you want to utilize these assets to unit test your release build(s) as well, release.assets.srcDirs does the trick. Thanks!

Was this page helpful?
0 / 5 - 0 ratings