[英]How to run Robolectric with Flurry on Android
When I try to run My robolectric tests, It throws a weird exception because of Flurry methods.当我尝试运行我的 robolectric 测试时,由于 Flurry 方法,它会抛出一个奇怪的异常。
It is error that I came across.这是我遇到的错误。
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)
It is my MainApplication.java:21这是我的 MainApplication.java:21
FlurryAgent.setLogEnabled( true );
Thank you for help.谢谢你的帮助。
It is hard to set up and run tests for static methods.很难为静态方法设置和运行测试。 Usually, people involve
PowerMock
to do that.通常,人们会使用
PowerMock
来做到这一点。
I would suggest you to wrap Flurry
logging with your class.我建议您将
Flurry
logging 与您的课程一起包装。
Pluses优点
Minuses缺点
You currently have the issue with unit testing your code.您目前在对代码进行单元测试时遇到问题。
So I would do it in next steps:所以我会在接下来的步骤中做到这一点:
Analytics
that responsible for reportingAnalytics
You can also solve your problem it in short term:您也可以在短期内解决您的问题:
Move call of the Analytics
initialization into protected method of the app class:将
Analytics
初始化的调用移动到应用程序类的受保护方法中:
public class YourAppClassName { protected void initAnalytics(){ FlurryAgant.setLogEnabled(true);公共类 YourAppClassName { protected void initAnalytics(){ FlurryAgant.setLogEnabled(true); } }
} }
Add Test<YourAppClassName>
into your test folder:将
Test<YourAppClassName>
添加到您的测试文件夹中:
public class Test{}公开课测试{}
Override Analytics
initialisation in test application:覆盖测试应用程序中的
Analytics
初始化:
protected void initAnalytics(){} protected void initAnalytics(){}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.