Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android project with Robolectric and Gradle (Android studio)

I'm trying to use Robolectric in a project build with gradle inside the new Ide for android: Android studio, but I'm facing a strange problem, I've correctly imported all the libraries and created the "test" folder inside "src", the fact is that whenever I run the tests the ide keep saying "Class not found: "com.example.myandroidproject.test" what I'm doing wrong? i need to change something in the gradle.build? here's my directory structure:

enter image description here

like image 920
Flying Mongoose Avatar asked May 28 '13 19:05

Flying Mongoose


People also ask

Is Robolectric deprecated?

setupActivity() is deprecated in Android unit test. Save this question.

What are the disadvantages of using Robolectric?

So the main benefit about Robolectric is that it is a lot faster than Espresso or Instrumented tests in general. The downside is that it fakes an Android environment which you should be aware of. To validate real world problems, better use a classic Android Framework approach.

What is Robolectric used for?

Robolectric provides a JVM compile version of the android. jar file. Robolectric handles views, resource loading, and many other things that are implemented in the Android native. This enables you to run your Android tests in your development environment, without requiring any other setup to run the test.


1 Answers

@Aldo Borrero, finally it seems that someone has found the way to test android projects under "Android Studio" using Robolectric and Gradle. Please, take a look at this answer Robolectric with Gradle

Update: The guys from square have released a plugin to make Robolectric work out of the box with Gradle and Android Studio, this feature will be integrated with Robolectric in v2, meanwhile you can grab the plugin here: Gradle Android test Plugin

like image 71
Imanol Avatar answered Oct 18 '22 14:10

Imanol