When running Android unit tests with the maxParallelFork flag set to > 1 and cleaning both gradle cache (~/.gradle/caches/) AND maven cache (~/.m2/repository/) the build succeeds but the tests start failing with exception:
Unable to resolve artifact: Unable to get dependency information: Unable to read the metadata file for artifact 'org.robolectric:shadows-core:jar:16': Failed to build model from file '/Users/nicoloparolini/.m2/repository/org/robolectric/shadows-core/3.0/shadows-core-3.0.pom'.
Error: 'no more data available - expected end tags </configuration></plugin></plugins></build></project> to close start tag <configuration> from line 131 and start tag <plugin> from line 128 and start tag <plugins> from line 119 and start tag <build> from line 105 and start tag <project> from line 2, parser stopped on TEXT seen ...</generatedSourcesDirectory>\n </con... @133:14' for project org.robolectric:shadows-core
org.robolectric:shadows-core:jar:3.0
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
Caused by:
org.apache.maven.artifact.resolver.ArtifactResolutionException: Unable to get dependency information: Unable to read the metadata file for artifact 'org.robolectric:shadows-core:jar:16': Failed to build model from file '/Users/nicoloparolini/.m2/repository/org/robolectric/shadows-core/3.0/shadows-core-3.0.pom'.
Error: 'no more data available - expected end tags </configuration></plugin></plugins></build></project> to close start tag <configuration> from line 131 and start tag <plugin> from line 128 and start tag <plugins> from line 119 and start tag <build> from line 105 and start tag <project> from line 2, parser stopped on TEXT seen ...</generatedSourcesDirectory>\n </con... @133:14' for project org.robolectric:shadows-core
org.robolectric:shadows-core:jar:3.0
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
Caused by:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException: Unable to read the metadata file for artifact 'org.robolectric:shadows-core:jar:16': Failed to build model from file '/Users/nicoloparolini/.m2/repository/org/robolectric/shadows-core/3.0/shadows-core-3.0.pom'.
Error: 'no more data available - expected end tags </configuration></plugin></plugins></build></project> to close start tag <configuration> from line 131 and start tag <plugin> from line 128 and start tag <plugins> from line 119 and start tag <build> from line 105 and start tag <project> from line 2, parser stopped on TEXT seen ...</generatedSourcesDirectory>\n </con... @133:14' for project org.robolectric:shadows-core
Caused by:
org.apache.maven.project.ProjectBuildingException: Failed to build model from file '/Users/nicoloparolini/.m2/repository/org/robolectric/shadows-core/3.0/shadows-core-3.0.pom'.
Error: 'no more data available - expected end tags </configuration></plugin></plugins></build></project> to close start tag <configuration> from line 131 and start tag <plugin> from line 128 and start tag <plugins> from line 119 and start tag <build> from line 105 and start tag <project> from line 2, parser stopped on TEXT seen ...</generatedSourcesDirectory>\n </con... @133:14' for project org.robolectric:shadows-core
Caused by:
java.io.EOFException: no more data available - expected end tags </configuration></plugin></plugins></build></project> to close start tag <configuration> from line 131 and start tag <plugin> from line 128 and start tag <plugins> from line 119 and start tag <build> from line 105 and start tag <project> from line 2, parser stopped on TEXT seen ...</generatedSourcesDirectory>\n </con... @133:14
The files are however present and in good shape. Running the same test suite without parallel mode works fine.
Expected result: the tests should run with both parallel mode enabled and disabled.
Steps to reproduce:
Create a simple test project following these instructions:
http://robolectric.org/getting-started/
http://robolectric.org/writing-a-test/
Use this as your build.gradle for the app module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.robolectrictest.robotest"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
testOptions.unitTests.all {
testLogging {
events "failed", "skipped"
showStackTraces = true
exceptionFormat = "full"
}
maxParallelForks = 8
forkEvery = 20
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
androidTestCompile 'junit:junit:4.12'
}
Then create more test classes to trigger parallel mode (you can use the following python script)
for j in range(1, 200):
testClassStart = """package com.robolectrictest.robotest;
import android.content.Intent;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import junit.framework.Assert;
import org.robolectric.Robolectric;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class ExampleUnitTest""" + str(j) + """ {"""
testClassEnd = "}"
testFile = open("ExampleUnitTest" + str(j) + ".java", "w")
testFile.write(testClassStart)
for i in range(1, 10):
testContent = """@Test
public void addition_isCorrect""" + str(j) + "_" + str(i) + """() throws Exception {
MainActivity activity = Robolectric.setupActivity(MainActivity.class);
Assert.assertTrue(true);
}"""
testFile.write(testContent)
testFile.write(testClassEnd)
testFile.close()
Try running ./gradle test, it should fail with the aforementioned exception.
I have the test project in a zipfile, but as a new user I am unable to attach it, I can provide it if needed.
Tried with gradle 2.11.