Created
September 29, 2019 20:55
-
-
Save singhangadin/8751e6eb19e8731ade3ee8ea2a6231cf to your computer and use it in GitHub Desktop.
Testing Room Migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
public class DatabaseInstrumentedTest { | |
private static final String TEST_DB_NAME = "test_database"; | |
@Rule | |
public MigrationTestHelper testHelper = | |
new MigrationTestHelper( | |
InstrumentationRegistry.getInstrumentation(), | |
TestDatabase.class.getCanonicalName(), | |
new FrameworkSQLiteOpenHelperFactory() | |
); | |
@Test | |
public void testAllMigrations() throws IOException { | |
testHelper.createDatabase(TEST_DB_NAME, 1); | |
testHelper.runMigrationsAndValidate(TEST_DB_NAME, Constants.DB_VERSION, true, migrations); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DatabaseModule { | |
private static final Migration MIGRATION_1_2 = new Migration(1, 2) { | |
@Override | |
public void migrate(SupportSQLiteDatabase database) { | |
database.execSQL("DROP TABLE IF EXISTS dummy_table"); | |
} | |
}; | |
@NonNull | |
public static Migration[] migrations = { | |
MIGRATION_1_2 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment