Does anyone out there use Robolectric without Maven on IntelliJ?

All Robolectric usage examples that I can find seem to be based on Maven. Does anyone not use Maven? If so, I would really like to understand your setup of the IntelliJ project.

After reading this post

Android Testing Approaches

It seems reasonable to have a multi-level approach to individual projects of the android testig project with a combination of pure junit, robolectric and android tests. If anyone who does this with or without Maven, I would like to know a little about how you set up your projects in IntelliJ.

I assume that I will need several projects / modules. Any wisdom on this was gratefully received.

+8
android maven unit-testing robolectric
source share
3 answers

Maven is a great tool to make things more convenient. If you are still looking for a way to install Robolectric inside Intellij WITHOUT Maven, follow these steps:

  • Download Robolectric: https://oss.sonatype.org/index.html#nexus-search;quick~robolectric download the latest jar-with-dependencies.jar file. Download it and put it in the libs / directory of your application project.

  • configure the application source with the following file structure (this is a widely used method for setting up your directories for Robolectric testing)

    ProjectName/ src/ main/ java/ com/ example/ packageName/ javaClassesHere.java test/ java/ com/ example/ packageName/ javaTestClassesHere.java 
  • In Intellij, go to File> Project Structure. Then in the left column select "Modules".
    In the middle column, select your application module.
    Then in the right column go to the Sources tab.
    Now in the file browser, locate the "src" directory and expand it. Then expand both your "main" and "test" directories inside src. Click "java" in the "main" section, then up, click the blue "Sources" button. Then, for the "java" directory in the "test" section, click the "Test Sources" button.
    Alternatively, click on the "src" main directory and the DEselect the blue sources button to make it non-blue.

  • Now, in the project structure window, go to the left column and click "Libraries".
    If you see the entry for robolectric in the middle column, click on it, then click the red “-” button, go to the top of the middle column.
    Now click the green “+” sign above the middle column and select “Java”. Go to your robolectric jar, which you downloaded in step 1. (should be in your libs / directory of your project.
    A window will appear asking which modules you want to use robolectric. Select all the modules that robolectric will use, and click OK. Now click "Apply" and "OK" to exit the project structure.

You are now set up for testing with robolectric!

+6
source share

I assume that the reason most people use Robolectric is using Maven because most people who try to use Roboelectric take their testing seriously.

Given that they are motivated to make serious efforts in testing, they are likely to want to include their tests in an automatic assembly, usually on a continuous integration (CI) server such as Jenkins or Hudson.

If you want to do automated testing, you need a good build on the command line. Gradle is the new official command line building tool for Android, but, being completely new, is still under development and has not yet received wide distribution. A proven tool is Maven.

Many love to hate Maven, but he does his job and hits Ant for a mile.

Thus, it may not be a bad idea to use Maven (or Gradle) - it will give you a much better chance for your testing than just running your tests in your IDE.

+3
source share

I am an early bird in the Roboelectric sky and started by not following the Maven path. My main motivation was to try out the structure and, therefore, I never thought about using Maven. I have documented my knowledge on:
http://dasherize.blogspot.in/2013/04/robolectric-beginning.html
and you can find installation instructions here .

Note. This applies to Robolectric 1.x. But this should not change much when changing the version.

Regarding this answer , I totally agree with @GreyBeardedGeek. You need to settle with Maven if you want to configure CI.

+2
source share

All Articles