

We get very poor information on failing tests. We are forced to use Gradle from the command line.


We just lose the ability to rely on the IDE to speed up running tests and debugging. This hangup doesn’t entirely prevent us from using Robolectric with Gradle. For this reason we currently recommend IntelliJ we hope this can be solved in the future. You will get the dreaded Stub! exception every time you re-open the project (and possibly more often).
#ANDROID STUDIO GRADLE FILETREE ANDROID#
iml file) and subverts the technique used above to get the Android SDK to the bottom of the classpath. The Robolectric documentation says:Īndroid Studio aggressively re-writes your dependencies list (your. iml file for us, so there is no way to prioritize these dependencies by manually setting the order of the entries. For this “core” module, the adle file is relatively simple:Īt .(BaseTestRunner.java:5)Īt .(TestRunner.java:54)Īt .(TestRunner.java:48)Īt .(TestRunner.java:41)Īndroid Studio builds the dependency. Under “Project Structure,” click “+” and then select “Java Library.” Android Studio will generate the folder structure for this module and provide us with a separate adle file. Setting up a Java module in Android Studio is straightforward.
#ANDROID STUDIO GRADLE FILETREE TV#
Android Mobile, Android TV and Android Wear apps can all depend on this model layer module.Breaking the model out into its own module allows us to reuse it across different projects and platforms.We can test this module outside of Robolectric, relying on Junit tests alone.Breaking this layer out into its own Android Studio module provides us with several benefits: This means that there’s no dependency on the Android framework. Our consulting projects are usually architected in multiple layers, with the model layer coded in pure Java. We’ve put together a set of best practices for setting up a project that uses Android Studio, Gradle and Robolectric. While we haven’t come to a decision about which architecture is best for us-and this is always subject to change-we realized that Android Studio modules would help us achieve this separation. All of the many patterns we discuss rely on implementing some separation of concerns. We’ve spent a lot of brainpower thinking about different design architectures and patterns. We are already building expertise with Gradle and will continue using these skills. We wanted to continue to rely on Robolectric as we moved to Android Studio, and as a consequence, the Gradle build system.Having our testing tool run seamlessly within our IDE allowed us very fast turnaround on a red/green/refactor workflow.Configuring Robolectric within IntelliJ + Maven allowed us to easily run tests from within the IDE, get immediate visual feedback, run subsets of tests and debug and set breakpoints within tests.In our consulting projects, we’ve benefited from building a solid set of unit tests with Robolectric, for a few reasons: Android Studio recently moved out of beta, so now is a good time to share about our successes so far. However, we still had trouble integrating some of the tools and techniques that made our past projects so successful. This shift has allowed us to build a uniform skillset, enhancing both our teaching and consulting. In May of 2014, we made the switch to Android Studio as our preferred Android IDE, migrating away from Eclipse in our Android bootcamps and book.Īs we have started new app development projects for clients, we transitioned away from IntelliJ, our previous IDE of choice. UPDATE: This post has been superseded by a newer version here.
