Intereting Posts

Запуск теста Android с Robolectric – ошибка зависимости

Я использую Android Studio 1.2 и Windows 7

При выполнении теста robolectric в следующем примере :

@RunWith(CustomRobolectricRunner.class) @Config(emulateSdk = 21, reportSdk = 21, constants = BuildConfig.class) public class PasswordProviderTest{ @Test public void testGetPassword() throws Exception { Activity activity = Robolectric.setupActivity(LoginActivity.class); } @Test public void testSetPassword() throws Exception { } } 

Результат теста или больше ошибка stacktrace:

  Unable to resolve artifact: Unable to get dependency information: Unable to read the metadata file for artifact 'org.robolectric:android-all:jar': Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 from the specified remote repositories: sonatype (https://oss.sonatype.org/content/groups/public/), central (http://repo1.maven.org/maven2) Path to dependency: 1) org.apache.maven:super-pom:pom:2.0 at org.apache.maven.artifact.ant.DependenciesTask.doExecuteResolution(DependenciesTask.java:268) at org.apache.maven.artifact.ant.DependenciesTask.doExecute(DependenciesTask.java:168) at org.apache.maven.artifact.ant.AbstractArtifactTask.execute(AbstractArtifactTask.java:751) at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrls(MavenDependencyResolver.java:40) at org.robolectric.internal.dependency.CachedDependencyResolver.getLocalArtifactUrls(CachedDependencyResolver.java:42) at org.robolectric.RobolectricTestRunner.createRobolectricClassLoader(RobolectricTestRunner.java:151) at org.robolectric.RobolectricTestRunner.createSdkEnvironment(RobolectricTestRunner.java:122) at org.robolectric.RobolectricTestRunner$3.create(RobolectricTestRunner.java:285) at org.robolectric.internal.EnvHolder.getSdkEnvironment(EnvHolder.java:18) at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:283) at org.robolectric.RobolectricTestRunner.access$300(RobolectricTestRunner.java:50) at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:193) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 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:168) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360) at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.maven.artifact.resolver.ArtifactResolutionException: Unable to get dependency information: Unable to read the metadata file for artifact 'org.robolectric:android-all:jar': Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 from the specified remote repositories: sonatype (https://oss.sonatype.org/content/groups/public/), central (http://repo1.maven.org/maven2) Path to dependency: 1) org.apache.maven:super-pom:pom:2.0 at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:430) at org.apache.maven.artifact.resolver.DefaultArtifactCollector.collect(DefaultArtifactCollector.java:74) at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:316) at org.apache.maven.artifact.ant.DependenciesTask.doExecuteResolution(DependenciesTask.java:263) ... 46 more Caused by: org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException: Unable to read the metadata file for artifact 'org.robolectric:android-all:jar': Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:200) at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedArtifact(MavenMetadataSource.java:94) at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:387) ... 49 more Caused by: org.apache.maven.project.ProjectBuildingException: Cannot find parent: org.sonatype.oss:oss-parent for project: org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 for project org.robolectric:android-all:jar:5.0.0_r2-robolectric-1 at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1396) at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:823) at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:255) at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:163) ... 51 more Caused by: org.apache.maven.project.ProjectBuildingException: POM 'org.sonatype.oss:oss-parent' not found in repository: Unable to download the artifact from any repository org.sonatype.oss:oss-parent:pom:7 from the specified remote repositories: sonatype (https://oss.sonatype.org/content/groups/public/), central (http://repo1.maven.org/maven2) for project org.sonatype.oss:oss-parent at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:605) at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1392) ... 54 more Caused by: org.apache.maven.artifact.resolver.ArtifactNotFoundException: Unable to download the artifact from any repository org.sonatype.oss:oss-parent:pom:7 from the specified remote repositories: sonatype (https://oss.sonatype.org/content/groups/public/), central (http://repo1.maven.org/maven2) at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:228) at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:90) at org.apache.maven.pr oject.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:558) ... 55 more Caused by: org.apache.maven.wagon.ResourceDoesNotExistException: Unable to download the artifact from any repository at org.apache.maven.artifact.manager.DefaultWagonManager.getArtifact(DefaultWagonManager.java:404) at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:216) ... 57 more 

Зависимостей построения градиента:

 testCompile 'junit:junit:4.12' testCompile "org.mockito:mockito-core:1.9.5" testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' testCompile "org.robolectric:robolectric:3.0-rc2" 

Я узнаю, что ресурс, robolectric пытается получить, не доступен. Следуя URL-адресу, он пытается его получить: https://oss.sonatype.org/content/groups/public/org/sonatype/oss/oss-parent/

Нет oss 7. Почему robolectrics пытается получить ресурс, которого нет? И как заставить его работать?

Кажется, это проблема прокси. Когда за прокси-сервером вы должны указать параметры прокси-сервера для maven в {userHome} /. M2 / settings.xml

My settings.xml теперь выглядит так:

 <settings> <proxies> <proxy> <active>true</active> <host>proxy.host</host> <port>3128</port> </proxy> </proxies> </settings> 

Ниже не работает !!

 <settings> <proxies> <proxy> <id>proxy-https</id> <active>true</active> <protocol>https</protocol> <host>proxy.host</host> <port>3128</port> </proxy> <proxy> <id>proxy-http</id> <active>true</active> <protocol>http</protocol> <host>proxy.host</host> <port>3128</port> </proxy> </proxies> </settings>