问题
I am developing some JUnit test for ma app. I need to use Robolectric + Roboguice libraries. What I am trying to do now is only simple test which checks if activity is not null.
Here is my code:
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP,
application = TestBoomerangManagerApplication.class,
manifest = "src/main/AndroidManifest.xml")
public class SimpleTest {
private DirectInviteEmployeesActivity activity;
@Before
public void setup() {
activity = Robolectric.buildActivity(DirectInviteEmployeesActivity
.class).create().get();
}
@Test
public void shouldNotBeNull() {
assertThat(activity).isNotNull();
Button button = (Button) activity.findViewById(R.id.btn_send_invites);
assertThat(button).isNotNull();
}
@Test
public void shouldFail() {
assertTrue(true);
}
}
It is really simple and should work, but when I am trying to run my test it comes with error:
java.lang.IllegalArgumentException: INTERNET permission is required.
at com.segment.analytics.Analytics$Builder.<init>(Analytics.java:597)
at com.segment.analytics.Analytics.with(Analytics.java:116)
at com.jobtapteam.shared.utils.AnalyticsUtil.sendPageView(AnalyticsUtil.java:90)
at com.jobtapteam.shared.ui.AbstractActivity.onCreate(AbstractActivity.java:153)
at com.jobtapteam.employer.ui.activity.DirectInviteEmployeesActivity.onCreate(DirectInviteEmployeesActivity.java:73)
at android.app.Activity.performCreate(Activity.java:5933)
at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:304)
at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
at org.robolectric.util.ActivityController.create(ActivityController.java:118)
at org.robolectric.util.ActivityController.create(ActivityController.java:129)
at SimpleTest.setup(SimpleTest.java:33)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
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:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Obviously I have added Internet permission to manifest file. I have no idea what I am doing wrong. Please help ! :)
来源:https://stackoverflow.com/questions/32740070/robolectric-junit-test-missing-internet-permission