Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Unit testing with model objects

Sam Bosley edited this page Oct 20, 2015 · 2 revisions

SquiDB model objects rely on some Android classes and methods to function properly, most notably ContentValues and TextUtils. As described in this document, the android.jar file used to run unit tests in Android studio uses mocked versions of these classes rather than real implementations. The upshot here is that methods on model objects will not work properly in this unit test environment -- you may see errors like "null not found in model" when calling model getters/setters, or have unexpected values returned from the getters. If you are writing tests that use model objects to verify behavior, we recommend that you either a) write integration tests that run directly on a device or emulator, or b) use Robolectric to run the unit tests in question:

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.JELLY_BEAN)
public class ModelBehaviorTest {
    ...
}