我曾尝试使用 greenDAO 示例应用程序在 JUnit 中编写测试用例,但我得到了由 InvocationTargetException 引起的 RuntimeException:
它甚至不运行测试。
以下是令人讨厌的代码:
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;
}
}
有什么我想念的吗?
我有一个 Android 应用程序,测试在一个单独的应用程序中。我在生成代码时指出了这一点:
schema.setDefaultJavaPackageTest("com.ralphpina.greenDao.test");
schema.setDefaultJavaPackageDao("com.ralphpina.greenDao.greendao");
我有正确定位应用程序的仪器。我有一大堆运行良好的 JUnit 测试用例。
我在两个应用程序中都包含了 greenDAO.jar,并且我仔细检查了它是否在构建路径中。
我的 Eclipse 环境中有笔记示例应用程序,并且 JUnit 测试在那里运行良好。所以我的项目中必须有一些特定的东西。有什么建议么?
完整例外的文本:
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
更新:
我可以通过将 greenDAO 中生成的类复制并粘贴到我的测试项目中来运行 JUnit。显然,这并不理想,因为现在我必须记住更新它们。JUnit 是否有原因找不到 greenDAO 类,但在我的目标 Android 项目中查看所有其他类没有问题?