Learn Android Development

Easy and quick experiment of your project’s code in Android Studio

Image for post
Image for post

I work on an App that has 100k methods count, with hundreds of classes. It took several minutes to compile, even when Instance Run is turned on.

Now if I want to perform a little experiment on some of the classes interacting with one another, and doesn’t needfully integration of the App flow (e.g. testing out some JSON deserializing on some classes), how could I achieve it?

(Skip the 3 options below and go to The Easy and Quick Way, if you want to be quick)

I could add the code in the place I want that to use; compile and run it.

But it just took so long and too much hassle, if I need several iterations of the experiment to get things right. Testing using the actual code is just too troublesome.

I could create a separate module in my App and have it run.

But really do I have to add a module just to do that? This will add an unnecessary modules to my project. Adding and removing them would not be fun.

Treat like a different project, either relying on Android Studio or another external Java project.

Oh… I need to copy all my classes over to do that, and all the code dependencies would need to be setup. I don’t want to do that.

The Easy and Quick Way!

You know what? In your app project, you already have the test module, and it does have all the dependencies set up, and linked to all classes of your app easily. I know it’s meant for Unit Test…. but isn’t it that you could write something like

private void doMyExperiment() {
MyComplex class = new MyComplex(...);
// Do your experiment here.
class AnExperimentClass() {
// You could define an experiment class if you like to
// be used by your experiment

Run it like running a unit test. Just run or debug as you like. No setup needed. Compiled and run like lightning-fast in seconds. And easily removed when you don’t need it. … Also as a bonus, it could also be converted to be your Unit Test later with slight modification perhaps :)

Written by

Passionate about learning, and sharing mobile development and others https://twitter.com/elye_project https://www.facebook.com/elye.proj

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store