Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Sugar #96

Open
jivimberg opened this issue May 10, 2014 · 13 comments
Open

Testing Sugar #96

jivimberg opened this issue May 10, 2014 · 13 comments
Assignees

Comments

@jivimberg
Copy link
Contributor

Hi I was wondering if anyone was able to make sugar work with Robolectric.
I wrote a save tests and keep getting

java.lang.NullPointerException
    at dalvik.system.DexFile$DFEnum.hasMoreElements(DexFile.java:239)
    at com.orm.SugarDb.getDomainClasses(Unknown Source)
    at com.orm.SugarDb.createDatabase(Unknown Source)
    at com.orm.SugarDb.onCreate(Unknown Source)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
    at com.orm.Database.openDB(Unknown Source)
    at com.orm.SugarRecord.save(Unknown Source)

Any pointer would be appreciated

@jamiecramb
Copy link

+1

2 similar comments
@samurai-thoughtworks
Copy link

+1

@parmalazs
Copy link

+1

@whoshuu
Copy link
Collaborator

whoshuu commented Jul 4, 2014

+1 as well, Roboelectric is a great tool. I'll take a look into why this is happening within the next week.

@whoshuu whoshuu self-assigned this Jul 4, 2014
@parmalazs
Copy link

java.lang.NullPointerException
at dalvik.system.DexFile$DFEnum.hasMoreElements(DexFile.java:239)
at hu.pont.ormrec.OrmRecDb.getDomainClasses(OrmRecDb.java:41)
at hu.pont.ormrec.OrmRecDb.createDatabase(OrmRecDb.java:108)
at hu.pont.ormrec.OrmRecDb.onCreate(OrmRecDb.java:104)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at hu.pont.ormrec.Database.getDB(Database.java:18)
at hu.pont.ormrec.OrmRecApp.onTerminate(OrmRecApp.java:16)
at org.robolectric.internal.ParallelUniverse.tearDownApplication(ParallelUniverse.java:170)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:260)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

@whoshuu whoshuu closed this as completed in 3c47b24 Jul 8, 2014
@mlix11
Copy link

mlix11 commented Jan 17, 2015

I get the same error. My dependency is compile 'com.github.satyan:sugar:1.3' . what can I do?

@d0minicw0ng
Copy link
Contributor

+1

@mlix11
Copy link

mlix11 commented Feb 5, 2015

I have the solution. Easy as hell.
You have to create a package com.orm with the class TestSugarApp. The Class looks like this:

@RunWith(RobolectricTestRunner.class)
@Config(manifest="./src/main/AndroidManifest.xml",emulateSdk=18)
public class TestSugarApp extends Application
    implements TestLifecycleApplication {



@Test
public void startEverTestSugarAppAsFirst() {

}

@Override
public void beforeTest(Method method) {
    Log.v("test", "beforeTest");
}

@Override
public void prepareTest(Object test) {
    Log.v("test", "prepareTest");
}

@Override
public void afterTest(Method method) {
    Log.v("test", "afterTest");
}
}

After that all tests worked out for me :)

@leenasn
Copy link

leenasn commented Aug 4, 2015

Does it make sense to add a it as part of the Wiki. If yes, I can submit a pull request for the same.

@mlix11
Copy link

mlix11 commented Aug 4, 2015

Make sense +1

I can do that, or ref to my post ;)

@leenasn
Copy link

leenasn commented Aug 5, 2015

ok. @loose11 are you taking care of the same?

@clay-to-n
Copy link

@loose11, I've created that package in test/java, and made that file (with imports and "package com.orm;" at the top) in my project.

I still get the same error, even in that new test file. On sugar 1.3.1. Using a custom Application class that extends SugarApp. Any idea what I could be missing?

@pickeyboy
Copy link

@loose11 I face exactly the same problem @clay-to-n is facing. Is there any solution ?

My Application class is also extending SugarApp and I get the same exception even after adding TestSugarApp under com.orm package.

@sibelius sibelius reopened this Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests