Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Android上使用Flurry运行Robolectric_Java_Android_Tdd_Robolectric - Fatal编程技术网

Java 如何在Android上使用Flurry运行Robolectric

Java 如何在Android上使用Flurry运行Robolectric,java,android,tdd,robolectric,Java,Android,Tdd,Robolectric,当我尝试运行我的机器人测试时,它抛出了一个奇怪的异常,因为使用了Flurry方法 我遇到的是错误 java.lang.VerifyError: Expecting a stackmap frame at branch target 17 Exception Details: Location: com/flurry/android/FlurryAgent.init(Landroid/content/Context;Ljava/lang/String;)V @5: if_icmpge

当我尝试运行我的机器人测试时,它抛出了一个奇怪的异常,因为使用了Flurry方法

我遇到的是错误

java.lang.VerifyError: Expecting a stackmap frame at branch target 17
Exception Details:
  Location:
    com/flurry/android/FlurryAgent.init(Landroid/content/Context;Ljava/lang/String;)V @5: if_icmpge
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0x0000000: b200 4f10 0aa2 000c b200 5012 06b8 007a
    0x0000010: b12a c700 0dbb 0044 5912 11b7 0089 bf2b
    0x0000020: c600 0a2b b600 8b9a 000d bb00 4159 1226
    0x0000030: b700 86bf b800 822a 2bb8 006e a700 0d4d
    0x0000040: b200 5012 012c b800 78b1               
  Exception Handler Table:
    bci [52, 60] => handler: 63


    at com.pepapp.MainApplication.onCreate(MainApplication.java:21)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:140)
    at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:433)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:240)
    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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
它是我的主应用程序

FlurryAgent.setLogEnabled( true );

谢谢您的帮助。

很难为静态方法设置和运行测试。通常情况下,人们会使用
PowerMock
来实现这一点

我建议您将
Flurry
日志记录打包到您的类中

加号

  • 您可以交换/添加分析,而无需触摸使用分析的应用程序类
  • 您可以单元测试代码是否正确触发分析
减号

  • 您需要编写更多的代码
您目前在单元测试代码时遇到问题

因此,我将在接下来的步骤中进行:

  • 创建负责报告的类
    Analytics
  • 在应用程序中实现适当的依赖项注入
  • 您也可以在短期内解决您的问题:

  • 分析
    初始化调用移动到应用程序类的受保护方法中:

    公共类YourAppClassName{ 受保护的void initAnalytics(){ FlurryAgant.setLogEnabled(true); } }

  • Test
    添加到您的测试文件夹中:

    公共类测试{}

  • 覆盖测试应用程序中的分析初始化:

    受保护的void initAnalytics(){}