2016-07-06 63 views
1

我使用Robolectric工具爲我的應用程序創建了一個簡單的junit測試。Robolectric給出例外

import org.junit.Before; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.robolectric.Robolectric; 
import org.robolectric.RobolectricGradleTestRunner; 
import org.robolectric.annotation.Config; 

import static org.junit.Assert.assertNotNull; 

@RunWith(RobolectricGradleTestRunner.class) 
@Config(constants = BuildConfig.class,sdk = 21) 
public class MainActivityTest { 
    MainActivity activity; 
    @Before 
    public void setUp(){ 
     activity= Robolectric.setupActivity(MainActivity.class); 
    } 

    @Test 
    public void shouldNotBeNull(){ 
    assertNotNull(activity); 
    } 
} 

基本上這個測試應該通過,因爲活動不爲空。但是,我得到這個奇怪的例外。

java.lang.IllegalArgumentException: path must be convex 

at android.graphics.Outline.setConvexPath(Outline.java:216) 
at android.graphics.drawable.GradientDrawable.getOutline(GradientDrawable.java:1441) 
at android.view.ViewOutlineProvider$1.getOutline(ViewOutlineProvider.java:38) 
at android.view.View.rebuildOutline(View.java:11116) 
at android.view.View.onAttachedToWindow(View.java:12960) 
at android.view.ViewGroup.onAttachedToWindow(ViewGroup.java:3815) 
at android.view.View.dispatchAttachedToWindow(View.java:13406) 
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2707) 
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714) 
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714) 
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714) 
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714) 
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714) 
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714) 
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1292) 
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054) 
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at org.robolectric.shadows.ShadowMessageQueue.dispatchMessage(ShadowMessageQueue.java:130) 
at org.robolectric.shadows.ShadowMessageQueue.access$100(ShadowMessageQueue.java:30) 
at org.robolectric.shadows.ShadowMessageQueue$1.run(ShadowMessageQueue.java:95) 
at org.robolectric.util.Scheduler$ScheduledRunnable.run(Scheduler.java:269) 
at org.robolectric.util.Scheduler.runOneTask(Scheduler.java:179) 
at org.robolectric.util.Scheduler.advanceTo(Scheduler.java:160) 
at org.robolectric.util.Scheduler.advanceBy(Scheduler.java:143) 
at org.robolectric.util.Scheduler.unPause(Scheduler.java:54) 
at org.robolectric.shadows.ShadowLooper.unPause(ShadowLooper.java:266) 
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:306) 
at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45) 
at org.robolectric.util.ActivityController.visible(ActivityController.java:173) 
at org.robolectric.util.ActivityController.setup(ActivityController.java:210) 
at org.robolectric.Robolectric.setupActivity(Robolectric.java:46) 
at team.football.ael.MainActivityTest.shouldNotBeNull(MainActivityTest.java:24) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251) 
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188) 
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 

任何想法發生了什麼?

謝謝,

泰奧。

+0

請參閱https://github.com/robolectric/robolectric/issues/1810,您使用的是什麼robolectric版本? – splatte

+0

我使用robolectric 3.0 – Theo

+1

更新到3.1應包含解決您的問題。 – splatte

回答