Element84 / AndroidTestExample

This is a simple example project showing how to use Roboelectric and JUnit to test Android code without needing to deploy it to a device.
Apache License 2.0
5 stars 5 forks source link

Run unit tests with Android Studio #1

Open mdumrauf opened 10 years ago

mdumrauf commented 10 years ago

Your approach is really good. Great work! It gives me the possibility of having unit tests with Robolectric that run on the CI Server.

Now I am trying to run them within the IDE. This is the error:

/usr/lib/jvm/java-6-oracle/bin/java -ea -Didea.launcher.port=7532 -Didea.launcher.bin.path=/home/matias/Programs/android-studio/bin -Dfile.encoding=UTF-8 -classpath /home/matias/Programs/android-studio/lib/idea_rt.jar:/home/matias/Programs/android-studio/plugins/junit/lib/junit-rt.jar:/usr/lib/jvm/java-6-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-6-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-6-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-6-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-6-oracle/jre/lib/rt.jar:/usr/lib/jvm/java-6-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-6-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-6-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-6-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-6-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-6-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-6-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-6-oracle/jre/lib/ext/sunpkcs11.jar:/home/matias/workspace/java/android/examples/AndroidTestExample/Starter/StarterApp/build/classes/debug com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 @/tmp/idea_junit4120993243480152132.tmp @w@/tmp/idea_working_dirs_junit1270216779940516155.tmp -socket52642
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:171)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 3 more

Process finished with exit code 1
mdumrauf commented 10 years ago

Looks like it is a known issue: https://groups.google.com/forum/#!searchin/adt-dev/android$20studio$20unit$20test/adt-dev/lgDdhQkjq_4/G7OkZtZZVYIJ

rekire commented 10 years ago

@mdumrauf Do you have any updates? I curriently added this the test as a external gradle task. How did you intergrate it?

mdumrauf commented 10 years ago

@rekire I managed to run it as an external gradle task too, but that makes it non-debuggable. I ended up running the task manually in a terminal and looking at the stacktrace in the html report. Sucks, really, but it's something.

maboueita commented 10 years ago

Following your approach, I could run the Test Sample. However when I started writing actual tests for my app I found some issues:

  1. On the first invocation of Robolectric I had "cannot find Symbol 'Robolectric'"
  2. It cannot resolve ActionBarActivity
  3. It cannot find my own activity classes in /src/main/java/..
mdumrauf commented 10 years ago

Looks like the Robolectric team has made some progress on it https://github.com/robolectric/deckard-gradle