我只是在针对使用GoogleAnalytics 1.4.2的 Android 应用程序试验 Robolectric 1.1 。
在每次调用 GoogleAnalyticsTracker trackPageView Robolectrics ShadowSQLiteDatabase 类时都会引发异常
java.lang.IllegalStateException: transaction already successfully
at com.xtremelabs.robolectric.shadows.ShadowSQLiteDatabase.setTransactionSuccessful(ShadowSQLiteDatabase.java:291)
at android.database.sqlite.SQLiteDatabase.setTransactionSuccessful(SQLiteDatabase.java)
at com.google.android.apps.analytics.PersistentHitStore.putEvent(Unknown Source)
at com.google.android.apps.analytics.GoogleAnalyticsTracker.createEvent(Unknown Source)
at com.google.android.apps.analytics.GoogleAnalyticsTracker.trackPageView(Unknown Source)
at uk.co.bmc.rad.util.Analytics.trackPageView(Analytics.java:78)
at uk.co.bmc.rad.ui.FindCragActivity.onCreate(FindCragActivity.java:95)
at uk.co.bmc.rad.roboelectric.activities.FindCragActivityTests.setUp(FindCragActivityTests.java:36)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at com.xtremelabs.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:292)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
该应用程序运行良好,如果我注释掉对 GoogleAnalyticsTracker 的调用,那么测试也运行良好。
我的设置中是否缺少某些内容或...