0

I have tried writing test cases in JUnit using the greenDAO sample app as an example, but I get a RuntimeException caused by InvocationTargetException:

JUnit error from greenDAO

It doesn't even run the tests.

Below is the code that is barfing this up:

import de.greenrobot.dao.test.*;

public class LibrarySummaryTest extends AbstractDaoTestLongPk<LibrarySummaryDao, LibrarySummary> {

    public LibrarySummaryTest() {
        super(LibrarySummaryDao.class);
    }

    @Override
    protected LibrarySummary createEntity(Long arg0) {
        // TODO Auto-generated method stub
        return null;
    }
}

Is there something I am missing?

I have an Android app, the tests are in a separate app. I indicated this when I generated the code:

schema.setDefaultJavaPackageTest("com.ralphpina.greenDao.test");
schema.setDefaultJavaPackageDao("com.ralphpina.greenDao.greendao");

I have the instrumentation correctly targeting the app. I have a whole bunch of JUnit test cases that run perfectly fine.

I have included the greenDAO.jar in both apps, and I have double checked that it is in the build path.

I have the notes sample app in my eclipse environment and the JUnit test runs fine there. So there must be something specific in my project. Any suggestions?

Text of full exception:

03-15 01:02:22.794: I/TestRunner(8775): java.lang.RuntimeException: Exception during suite construction
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238)
03-15 01:02:22.794: I/TestRunner(8775):     at java.lang.reflect.Method.invokeNative(Native Method)
03-15 01:02:22.794: I/TestRunner(8775):     at java.lang.reflect.Method.invoke(Method.java:511)
03-15 01:02:22.794: I/TestRunner(8775):     at junit.framework.TestCase.runTest(TestCase.java:168)
03-15 01:02:22.794: I/TestRunner(8775):     at junit.framework.TestCase.runBare(TestCase.java:134)
03-15 01:02:22.794: I/TestRunner(8775):     at junit.framework.TestResult$1.protect(TestResult.java:115)
03-15 01:02:22.794: I/TestRunner(8775):     at junit.framework.TestResult.runProtected(TestResult.java:133)
03-15 01:02:22.794: I/TestRunner(8775):     at junit.framework.TestResult.run(TestResult.java:118)
03-15 01:02:22.794: I/TestRunner(8775):     at junit.framework.TestCase.run(TestCase.java:124)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
03-15 01:02:22.794: I/TestRunner(8775):     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
03-15 01:02:22.794: I/TestRunner(8775): Caused by: java.lang.reflect.InvocationTargetException
03-15 01:02:22.794: I/TestRunner(8775):     at java.lang.reflect.Constructor.constructNative(Native Method)
03-15 01:02:22.794: I/TestRunner(8775):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184)
03-15 01:02:22.794: I/TestRunner(8775):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:379)
03-15 01:02:22.794: I/TestRunner(8775):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
03-15 01:02:22.794: I/TestRunner(8775):     at android.app.ActivityThread.access$1300(ActivityThread.java:141)
03-15 01:02:22.794: I/TestRunner(8775):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
03-15 01:02:22.794: I/TestRunner(8775):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 01:02:22.794: I/TestRunner(8775):     at android.os.Looper.loop(Looper.java:137)
03-15 01:02:22.794: I/TestRunner(8775):     at android.app.ActivityThread.main(ActivityThread.java:5039)
03-15 01:02:22.794: I/TestRunner(8775):     at java.lang.reflect.Method.invokeNative(Native Method)
03-15 01:02:22.794: I/TestRunner(8775):     at java.lang.reflect.Method.invoke(Method.java:511)
03-15 01:02:22.794: I/TestRunner(8775):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-15 01:02:22.794: I/TestRunner(8775):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-15 01:02:22.794: I/TestRunner(8775):     at dalvik.system.NativeStart.main(Native Method)
03-15 01:02:22.794: I/TestRunner(8775): Caused by: java.lang.NoClassDefFoundError: com.outridersw.tapinspectandroid.greendao.DaoMaster
03-15 01:02:22.794: I/TestRunner(8775):     at com.outridersw.tapinspectandroid.test.LibrarySummaryTest.<init>(LibrarySummaryTest.java:13)
03-15 01:02:22.794: I/TestRunner(8775):     ... 18 more

Update:

I was able to run JUnit by copying and pasting the generated classes in greenDAO into my test project. Obviously, this is not ideal, since now I have to remember to update them. Is there a reason JUnit can't find the greenDAO classes, but has no problems seeing all other classes in my target Android project?

1 Answer 1

1

It turns out the reason for this error is that I included the greenDAO.jar library in both the main and test Android projects. Once I deleted the jar from the project/libs folder I was able to run JUnit greenDAO tests without an issue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.