DEV Community

ck1703
ck1703

Posted on

java.io.FileNotFoundException: Cannot find the schema file in the assets folder

I am trying to test room database migration on robolectric . Robolectric version used 4.4. I am facing java.io.FileNotFoundException: Cannot find the schema file in the assets folder. Make sure to include the exported json schemas in your test assert inputs. See https://developer.android.com/training/data-storage/room/migrating-db-versions#export-schema for details

2021-08-03T17:50:07.733+0530 [DEBUG] [TestEventLogger] at androidx.room.testing.MigrationTestHelper.loadSchema(MigrationTestHelper.java:320)
2021-08-03T17:50:07.733+0530 [DEBUG] [TestEventLogger] at androidx.room.testing.MigrationTestHelper.createDatabase(MigrationTestHelper.java:152)
2021-08-03T17:50:07.733+0530 [DEBUG] [TestEventLogger] at com.excelfore.esync.agent.test.PREH2_1259.sequence(PREH2_1259.java:64)
2021-08-03T17:50:07.733+0530 [DEBUG] [TestEventLogger] at com.excelfore.esync.agent.test.support.TestBase.lambda$runTestSequence$8(TestBase.java:433)

Eventhough 1.json file present .

build.gradle :

javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/build/schemas".toString()]
}
}

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

testImplementation "androidx.room:room-testing:2.2.6"

Unit test code:

private static final String TEST_DB = "migration-test";

MigrationTestHelper helper = new MigrationTestHelper(InstrumentationRegistry.getInstrumentation(), ld + (MyDatabase.class.getCanonicalName()));
SupportSQLiteDatabase db = helper.createDatabase(TEST_DB, 1);

// Prepare for the next version.
db.close();

// Re-open the database with version 2 and provide
// MIGRATION_1_2 as the migration process.
db = helper.runMigrationsAndValidate(TEST_DB, 2, true, MyDatabase.MIGRATION_1_2);

Top comments (0)