【问题标题】:Android Local Unit Test returns error with a new IntentAndroid 本地单元测试返回带有新意图的错误
【发布时间】:2017-05-08 14:46:45
【问题描述】:

我正在尝试对 Android 方法进行简单的本地单元测试,但是当我调用 new Intent () 时,它返回错误:Method threw 'java.lang.RuntimeException' exception. Cannot evaluate android.content.Intent.toString()

我尝试了@mock Intent intent 和@PrepareForTest({Intent.class}),但我仍然遇到同样的错误...

我做错了吗?我还需要什么吗?我需要为此使用 Instrumented 测试吗?

代码如下:

@RunWith(MockitoJUnitRunner.class)
@PrepareForTest({Intent.class})
public class TimeFrameManagerTest
{

@Mock
Context mMockContext;


@Before
public void setUp ()
{

}


@Test
public void alarmSchedulePosteriorTime ()
{

    Intent intent = new Intent (); //Method threw 'java.lang.RuntimeException' exception. Cannot evaluate android.content.Intent.toString()

}


}

【问题讨论】:

    标签: android testing android-intent mocking mockito


    【解决方案1】:

    转到: 设置 -> 构建、执行、部署 -> 调试器 -> 数据视图 -> Java 并取消选中选项 Enable 'toString()' object view

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-23
      • 2020-11-20
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多