Question

I passed more than four hours in the internet looking for a way/tutorial/guide to install Robolectric in Eclipse/Maven , but I didn't find anything concrete.

I tried by adding the dependency in the POM, it doesn't work.

I tried as well to install it locally (create a new java-project and link to the test folder) just to test it, but it was not working as well (because the application is a maven one).

Can someone help me? Thanks for your time.

Was it helpful?

Solution

I just did it yesterday :)

Here's what I had to add into my pom.xml

Some versions

<fest-android.version>1.0.7</fest-android.version>
<robolectric.version>2.2</robolectric.version>
<junit.version>4.8.2</junit.version>
<android.test.version>4.2.2_r2</android.test.version>

Some dependencies

<!-- Test Dependencies  -->
<dependency>
  <groupId>com.squareup</groupId>
  <artifactId>fest-android</artifactId>
  <version>${fest-android.version}</version>
  <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.robolectric</groupId>
    <artifactId>robolectric</artifactId>
    <version>${robolectric.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
     <groupId>android</groupId>
     <artifactId>android</artifactId>
     <version>${android.test.version}</version>
     <scope>provided</scope>
 </dependency>

Obviously if you don't use fest-android, you don't need the version and dependency in your pom.

Surefire in the build tag

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.6</version>
      <configuration>
          <argLine>-Xmx1024m</argLine>
      </configuration>
  </plugin>

Point to your tests folder

By default, surefire looks for tests classes in /src/test/java , however if you changed that, configure the test folder just before the ending build tag as:

<testSourceDirectory>test</testSourceDirectory>

Done !

Cheers.

OTHER TIPS

This is a known issue with m2e-android and will be fixed in the next release:

https://github.com/rgladwell/m2e-android/issues/52

Please follow my Twitter feed or subscribe to the Maven Android Developers mailing list for updates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top