Изпълнявам модулен тест за Android и се опитвам да тествам възможността за проверка на разрешенията за време на изпълнение в Android. Мислех, че ще бъде лесно просто да създам тестов манифест под test
папка (НЕ androidTest
папка). като този,
Въпреки това хвърля изключения java.lang.IllegalArgumentException: failed to configure ..mysdk.myTest.myTest: couldn't find 'mysdk/src/test/AndroidManifest.xml'
Бях търсил това в Google няколко дни и не можах да намеря правилното решение за него. Бях прочел и няколко теми за stackoverflow. Но никой от тях не работи за мен (задайте $MODULE_DIR$
, нулирайте теста на модула в Edit Configuration
... и т.н.)
Ето тестовия код и аз просто използвам Android Studio без изграждане на проекта, за да стартирам тестовите случаи. (работи добре за тестови случаи, които не са свързани с манифест)
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, manifest =
"mysdk/src/test/AndroidManifest.xml")
public class myTest {
private Context context;
@Before
public void setUp() {
context = RuntimeEnvironment.application;
}
@Test
public void myTest() throws JSONException {
boolean hasWifiPermission context.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
== PackageManager.PERMISSION_GRANTED;
assertTrue(hasWifiPermission);
}
java.lang.IllegalArgumentException: failed to configure
mycompany.mysdk.myTest.mytest: couldn't find 'mysdk/src/test/AndroidManifest.xml'
at org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:256)
at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:426)
at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:351)
at com.intellij.junit4.JUnit4IdeaTestRunner.getDescription(JUnit4IdeaTestRunner.java:78)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
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:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.IllegalArgumentException: couldn't find 'mysdk/src/test/AndroidManifest.xml'
at org.robolectric.internal.DefaultManifestFactory.resolveFile(DefaultManifestFactory.java:58)
at org.robolectric.internal.DefaultManifestFactory.identify(DefaultManifestFactory.java:32)
at org.robolectric.RobolectricTestRunner.getAppManifest(RobolectricTestRunner.java:402)
at org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:243)
... 12 more
Използвам Android Studio 3.0.1 и Robolectric 3.5.1.