title: Android testing with Robolectric and AndroidAnnotations
body: <p>I've developing application using AndroidAnnotations and want to use Robolectric for unit testing.</p>
  
  <p>I can't get it working though.
  Application and tests are placed in single project.
  Source is placed under <code>/src/main/java</code> and test under <code>/src/test/java</code>. Both folders are source folders.</p>
  
  <p>When running test from Eclipse using Eclipse JUnit launcher I get:</p>
  
  <pre><code>Class not found org.demoapp.MyActivityTest
  java.lang.ClassNotFoundException: org.demoapp.MyActivityTest
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
  </code></pre>
  
  <p>When running from commandline <code>mvn clean test</code> I get:</p>
  
  <pre><code>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project demo-app: Compilation failure:
  [ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[3,16] package org.junit does not exist
  [ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[4,23] package org.junit.runner does not exist
  [ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[6,33] package com.xtremelabs.robolectric does not exist
  [ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[8,1] cannot find symbol
  [ERROR] symbol: class RunWith
  ...
  ...
  </code></pre>
  
  <p>Although all classes compiles in eclipse.</p>
  
  <p>Actually I don't know what's the problem here. Where should I start?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;org.demoapp&lt;/groupId&gt;
      &lt;artifactId&gt;demo-app&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;apk&lt;/packaging&gt;
      &lt;name&gt;Demo :: App&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;environment&gt;development&lt;/environment&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.android&lt;/groupId&gt;
              &lt;artifactId&gt;android&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
              &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.googlecode.libphonenumber&lt;/groupId&gt;
              &lt;artifactId&gt;libphonenumber&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-lang&lt;/groupId&gt;
              &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.googlecode.androidannotations&lt;/groupId&gt;
              &lt;artifactId&gt;androidannotations&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.googlecode.androidannotations&lt;/groupId&gt;
              &lt;artifactId&gt;androidannotations&lt;/artifactId&gt;
              &lt;classifier&gt;api&lt;/classifier&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.pivotallabs&lt;/groupId&gt;
              &lt;artifactId&gt;robolectric&lt;/artifactId&gt;
              &lt;version&gt;1.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.8.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;${project.artifactId}&lt;/finalName&gt;
  
          &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
  
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.6&lt;/source&gt;
                      &lt;target&gt;1.6&lt;/target&gt;
                      &lt;encoding&gt;UTF-8&lt;/encoding&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;com.jayway.maven.plugins.android.generation2&lt;/groupId&gt;
                  &lt;artifactId&gt;android-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.3.0&lt;/version&gt;
                  &lt;extensions&gt;true&lt;/extensions&gt;
                  &lt;configuration&gt;
                      &lt;manifest&gt;
                          &lt;debuggable&gt;true&lt;/debuggable&gt;
                      &lt;/manifest&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;manifestUpdate&lt;/id&gt;
                          &lt;phase&gt;process-resources&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;manifest-update&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;alignApk&lt;/id&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;zipalign&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
  
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.3.2&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;artifactId&gt;maven-jarsigner-plugin&lt;/artifactId&gt;
                      &lt;version&gt;1.2&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.5&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;encoding&gt;UTF-8&lt;/encoding&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
  
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                      &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
                      &lt;version&gt;1.5&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
                      &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
                      &lt;version&gt;1.0.0&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;lifecycleMappingMetadata&gt;
                              &lt;pluginExecutions&gt;
                                  &lt;pluginExecution&gt;
                                      &lt;pluginExecutionFilter&gt;
                                          &lt;groupId&gt;com.jayway.maven.plugins.android.generation2&lt;/groupId&gt;
                                          &lt;artifactId&gt;android-maven-plugin&lt;/artifactId&gt;
                                          &lt;versionRange&gt;[3.2.0,)&lt;/versionRange&gt;
                                          &lt;goals&gt;
                                              &lt;goal&gt;manifest-update&lt;/goal&gt;
                                          &lt;/goals&gt;
                                      &lt;/pluginExecutionFilter&gt;
                                      &lt;action&gt;
                                          &lt;execute /&gt;
                                      &lt;/action&gt;
                                  &lt;/pluginExecution&gt;
                              &lt;/pluginExecutions&gt;
                          &lt;/lifecycleMappingMetadata&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
      &lt;/build&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;development&lt;/id&gt;
              &lt;activation&gt;
                  &lt;property&gt;
                      &lt;name&gt;environment&lt;/name&gt;
                      &lt;value&gt;!production&lt;/value&gt;
                  &lt;/property&gt;
              &lt;/activation&gt;
              &lt;properties&gt;
                  &lt;deployment.stage&gt;In Development&lt;/deployment.stage&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;production&lt;/id&gt;
              &lt;properties&gt;
                  &lt;deployment.stage&gt;In Production&lt;/deployment.stage&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;release&lt;/id&gt;
              &lt;activation&gt;
                  &lt;property&gt;
                      &lt;name&gt;performRelease&lt;/name&gt;
                      &lt;value&gt;true&lt;/value&gt;
                  &lt;/property&gt;
              &lt;/activation&gt;
              &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                          &lt;artifactId&gt;maven-jarsigner-plugin&lt;/artifactId&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;signing&lt;/id&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;sign&lt;/goal&gt;
                                      &lt;goal&gt;verify&lt;/goal&gt;
                                  &lt;/goals&gt;
                                  &lt;phase&gt;package&lt;/phase&gt;
                                  &lt;inherited&gt;true&lt;/inherited&gt;
                                  &lt;configuration&gt;
                                      &lt;removeExistingSignatures&gt;true&lt;/removeExistingSignatures&gt;
                                      &lt;archiveDirectory /&gt;
                                      &lt;includes&gt;
                                          &lt;include&gt;${project.build.directory}/${project.artifactId}.apk&lt;/include&gt;
                                      &lt;/includes&gt;
                                      &lt;keystore&gt;keystore/keys.keystore&lt;/keystore&gt;
                                      &lt;alias&gt;alias&lt;/alias&gt;
                                      &lt;storepass&gt;${sign.storepass}&lt;/storepass&gt;
                                      &lt;keypass&gt;${sign.keypass}&lt;/keypass&gt;
                                      &lt;verbose&gt;true&lt;/verbose&gt;
                                  &lt;/configuration&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                      &lt;/plugin&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;com.jayway.maven.plugins.android.generation2&lt;/groupId&gt;
                          &lt;artifactId&gt;android-maven-plugin&lt;/artifactId&gt;
                          &lt;version&gt;3.3.0&lt;/version&gt;
                          &lt;inherited&gt;true&lt;/inherited&gt;
                          &lt;configuration&gt;
                              &lt;sign&gt;
                                  &lt;debug&gt;false&lt;/debug&gt;
                              &lt;/sign&gt;
                              &lt;zipalign&gt;
                                  &lt;verbose&gt;true&lt;/verbose&gt;
                                  &lt;inputApk&gt;${project.build.directory}/${project.artifactId}.apk&lt;/inputApk&gt;
                                  &lt;outputApk&gt;${project.build.directory}/${project.artifactId}-signed-aligned.apk
                                  &lt;/outputApk&gt;
                              &lt;/zipalign&gt;
                              &lt;manifest&gt;
                                  &lt;debuggable&gt;false&lt;/debuggable&gt;
                                  &lt;versionName&gt;${project.version}&lt;/versionName&gt;
                                  &lt;versionCodeAutoIncrement&gt;true&lt;/versionCodeAutoIncrement&gt;
                              &lt;/manifest&gt;
                              &lt;proguard&gt;
                                  &lt;skip&gt;true&lt;/skip&gt;
                              &lt;/proguard&gt;
                          &lt;/configuration&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;manifestUpdate&lt;/id&gt;
                                  &lt;phase&gt;process-resources&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;manifest-update&lt;/goal&gt;
                                  &lt;/goals&gt;
                              &lt;/execution&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;alignApk&lt;/id&gt;
                                  &lt;phase&gt;package&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;zipalign&lt;/goal&gt;
                                  &lt;/goals&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.google.android&lt;/groupId&gt;
                  &lt;artifactId&gt;android&lt;/artifactId&gt;
                  &lt;version&gt;2.3.1&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
                  &lt;version&gt;1.3.2&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.googlecode.libphonenumber&lt;/groupId&gt;
                  &lt;artifactId&gt;libphonenumber&lt;/artifactId&gt;
                  &lt;version&gt;5.1&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
                  &lt;artifactId&gt;gson&lt;/artifactId&gt;
                  &lt;version&gt;2.2.2&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;commons-lang&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.googlecode.androidannotations&lt;/groupId&gt;
                  &lt;artifactId&gt;androidannotations&lt;/artifactId&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.googlecode.androidannotations&lt;/groupId&gt;
                  &lt;artifactId&gt;androidannotations&lt;/artifactId&gt;
                  &lt;classifier&gt;api&lt;/classifier&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  &lt;/project&gt;
  </code></pre>