RushOrm icon indicating copy to clipboard operation
RushOrm copied to clipboard

How to perform tests using Robolectric

Open HDANILO opened this issue 10 years ago • 3 comments

I've trying to test my webservice layer which needs to instantiate some RushObjects without saving, and I'm getting this thrown:

Exception in thread "Thread-4" java.lang.NullPointerException
at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:295)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:171)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
at java.util.Arrays.sort(Arrays.java:472)
at java.util.Collections.sort(Collections.java:155)
at org.robolectric.res.ResBunch.put(ResBunch.java:34)
at org.robolectric.res.ValueResourceLoader.processNode(ValueResourceLoader.java:36)
at org.robolectric.res.XpathResourceXmlLoader.processResourceXml(XpathResourceXmlLoader.java:22)
at org.robolectric.res.ValueResourceLoader.processResourceXml(ValueResourceLoader.java:19)
at org.robolectric.res.XmlLoader.processResourceXml(XmlLoader.java:50)
at org.robolectric.res.DocumentLoader.loadResourceXmlFile(DocumentLoader.java:72)
at org.robolectric.res.DocumentLoader.loadFile(DocumentLoader.java:61)
at org.robolectric.res.DocumentLoader.load(DocumentLoader.java:42)
at org.robolectric.res.PackageResourceLoader.loadEverything(PackageResourceLoader.java:30)
at org.robolectric.res.PackageResourceLoader.doInitialize(PackageResourceLoader.java:17)
at org.robolectric.res.XResourceLoader.initialize(XResourceLoader.java:29)
at org.robolectric.res.XResourceLoader.getValue(XResourceLoader.java:53)
at org.robolectric.res.PackageResourceLoader.getValue(PackageResourceLoader.java:3)
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:316)
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:312)
at org.robolectric.shadows.ShadowAssetManager.getResourceText(ShadowAssetManager.java:69)
at android.content.res.AssetManager.getResourceText(AssetManager.java)
at android.content.res.Resources.getText(Resources.java:235)
at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:363)
at android.content.res.Resources.getText(Resources.java)
at android.content.res.Resources.getString(Resources.java:325)
at android.database.sqlite.SQLiteGlobal.getDefaultJournalMode(SQLiteGlobal.java:74)
at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:717)
at org.robolectric.shadows.ShadowContext.openOrCreateDatabase(ShadowContext.java:136)
at org.robolectric.shadows.ShadowContextWrapper.openOrCreateDatabase(ShadowContextWrapper.java:370)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at co.uk.rushorm.android.AndroidRushStatementRunner.runRaw(AndroidRushStatementRunner.java:37)
at co.uk.rushorm.core.RushCore$11.statementCreated(RushCore.java:425)
at co.uk.rushorm.core.implementation.ReflectionTableStatementGenerator.generateStatements(ReflectionTableStatementGenerator.java:46)
at co.uk.rushorm.core.RushCore.createTables(RushCore.java:421)
at co.uk.rushorm.core.RushCore.access$200(RushCore.java:39)
at co.uk.rushorm.core.RushCore$1.run(RushCore.java:105)
at java.lang.Thread.run(Thread.java:745)

There is no rush method being called in the test, just an instantiation of an rushobjects and insertion of some values

HDANILO avatar Apr 14 '15 03:04 HDANILO

I haven't done any testing against Robolectric so will have to look into this before I can comment. Even though your not saving any objects you will be still calling initialize which will attempt to create the database schema.

Definitely a valid feature request for it to work with Robolectric, but for now you will just have to make sure initialize is not called when testing.

Stuart-campbell avatar Apr 14 '15 10:04 Stuart-campbell

Thank you for the attention

HDANILO avatar Apr 14 '15 16:04 HDANILO

For work around, I created a class called RushAndroid on the package co.uk.rushorm.android in the test folder, that have the initialize method with stubbed implementation.

HDANILO avatar Apr 14 '15 23:04 HDANILO