如何对领域迁移进行单元测试? [英] How to unit test Realm migrations?

查看:54
本文介绍了如何对领域迁移进行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Realm 上对迁移进行单元测试.我的主要问题是:如何维护 RealmObject 的不同模式版本,以便能够创建旧对象的实例,进行迁移,然后根据新模式版本检查它是否正确?

Im trying to unit test a migration on Realm. My main question is: how can I maintain different schema versions of a RealmObject so as to be able to create a an instance of the old object, do the migration and then check if it is correct according the new schema version?

我开始尝试保留不同的模式版本,但它不会编译,因为对象具有相同的名称,尽管位于不同的包中.

I started by trying to keep the different schema versions but it wont compile since the objects have the same name, despite being on different packages.

推荐答案

在 Realm,我们通过将旧的 Realm 文件存储为资产来测试迁移机制(请参阅 https://github.com/realm/realm-java/tree/master/realm/realm-library/src/androidTest/assets),然后编写测试以在迁移测试后检查结果(请参阅 https://github.com/realm/realm-java/blob/master/realm/realm-library/src/androidTest/java/io/realm/RealmMigrationTests.java).

At Realm we test the migration mechanism by storing old Realm files as assets (see https://github.com/realm/realm-java/tree/master/realm/realm-library/src/androidTest/assets) and then write tests to check the result after a migration test (see https://github.com/realm/realm-java/blob/master/realm/realm-library/src/androidTest/java/io/realm/RealmMigrationTests.java).

这篇关于如何对领域迁移进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆