Android robolectric测试显示合并问题(android beacon library)

时间:2016-05-18 19:32:02

标签: android robolectric ibeacon-android android-ibeacon robolectric-gradle-plugin

我有简单的测试用例

@Config(constants = BuildConfig.class)
@RunWith(RobolectricGradleTestRunner.class)
public class BaseTest  {

   @Test
   public void startEverTestSugarAppAsFirst() {
       BeaconManager.setsManifestCheckingDisabled(true);
   }

}

不幸的是,跑步者遇到了明显的问题

  

了java.lang.RuntimeException:   org.altbeacon.beacon.BeaconManager $ ServiceNotDeclaredException:The   在AndroidManifest.xml中未正确声明BeaconService。如果   使用Eclipse,请验证您的project.properties   manifestmerger.enabled =真

     

在   org.robolectric.RobolectricTestRunner $ 2.evaluate(RobolectricTestRunner.java:256)     在   org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:193)     在   org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:56)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)at at   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)at at   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at at   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)at at   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)at at   org.robolectric.RobolectricTestRunner $ 1.evaluate(RobolectricTestRunner.java:159)     在org.junit.runners.ParentRunner.run(ParentRunner.java:363)at   org.junit.runner.JUnitCore.run(JUnitCore.java:137)at at   com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)     在   com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)     在   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)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)   引起:   org.altbeacon.beacon.BeaconManager $ ServiceNotDeclaredException:The   在AndroidManifest.xml中未正确声明BeaconService。如果   使用Eclipse,请验证您的project.properties   manifestmerger.enabled = true at   org.altbeacon.beacon.BeaconManager.verifyServiceDeclaration(BeaconManager.java:786)     在org.altbeacon.beacon.BeaconManager。(BeaconManager.java:252)     在   org.altbeacon.beacon.BeaconManager.getInstanceForApplication(BeaconManager.java:244)     在com.lucyapp.client.Client.onCreate(Client.java:67)at   org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:164)     在   org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:421)     在   org.robolectric.RobolectricTestRunner $ 2.evaluate(RobolectricTestRunner.java:252)     ......还有18个

我想知道是否有任何简单的工作。我一直在浏览android beacon library test文件夹和

BeaconManager.setsManifestCheckingDisabled(true);

无效

1 个答案:

答案 0 :(得分:0)

不知何故BeaconManager正在构建之前BeaconManager.setsManifestCheckingDisabled(true);的调用。诀窍是找出放置该行的位置,以便首先执行它。

查看堆栈跟踪,我看到BeaconManager是从第67行的com.lucyapp.client.Client.onCreate构建的:

...
org.altbeacon.beacon.BeaconManager.getInstanceForApplication(BeaconManager.java:244) at 
com.lucyapp.client.Client.onCreate(Client.java:67)
...

知道这一点,也许你可以弄清楚你可以放置BeaconManager.setsManifestCheckingDisabled(true);行的位置,以便在com.lucyapp.client.Client.onCreate(Client.java:67)

之前调用它