I am finding troubles in running Robolectric tests with parallel mode on over a clean Gradle and Maven cache.
This is build.gradle:
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'
}
Building on API 23 displays the same issue. If I clear the caches (by removing ~/.gradle/caches/ and ~/.m2/repository) and run
./gradlew clean test
I encounter the following exception(s):
com.robolectrictest.robotest.ExampleUnitTest1 > addition_isCorrect1_1 FAILED
Unable to resolve artifact: Unable to get dependency information: Unable to read the metadata file for artifact 'org.robolectric:shadows-core:jar:21': 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:21': 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:21': 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
Now, the file is there, correctly formatted, without any odd special character in it. Looks simply like the process has been interrupted while reading it.
More details: this is the Activity being tested
package com.robolectrictest.robotest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View button = findViewById(R.id.login);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, MainActivity.class));
}
});
}
}
With its layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/login"
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
And this is the test, repeated 10 times per class with 200 classes to trigger multithreading:
public class ExampleUnitTest1 {@Test
public void addition_isCorrect1_1() throws Exception {
MainActivity activity = Robolectric.setupActivity(MainActivity.class);
activity.findViewById(R.id.login).performClick();
Intent expectedIntent = new Intent(activity, MainActivity.class);
Assert.assertNotSame(Shadows.shadowOf(activity).getNextStartedActivity(), expectedIntent);
}
}
I could not find any related bug or issue anywhere. Any ideas?