Question

I have a chunk of Java code that is cross platform in the sense that it works on both the Oracle JVM and Android. I prefer to develop and run my unit tests on the Oracle JVM but need to test and run on Android as well. Thoughts or suggestions?

Was it helpful?

Solution

Put the Java code that runs on JVM and Android into its own project - Java library. Then you can build its JAR and run unit tests against it. Add it as a dependency to your Android project. There are a few samples that will guide you in the gradle-samples-*.zip at the bottom of http://tools.android.com/tech-docs/new-build-system page.

There are other way where you can use one of existing libraries that enable unit testing of Android code but their set up is usually non-trivial so I would recommend you to start with the approach outlined above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top