Monday, August 31, 2015

Thank You Traveloka

If you read my blog you'll notice that I joined Traveloka around 9 months ago. It was my first time working for a product company and it was a great experience. I've always worked for a service company before that.

Traveloka is an amazing company and the growth is staggering. I learned a lot about working with app at scale and the mobile app landscape. The experience gained is invaluable.

Around 4 years ago I had this idea about a social shopping app called nawaran. I built it in 3 months and launched it but the ecosystem wasn't ready. So I decided to shut it down.

A few months back I had a chat with some friends with a similar idea. They are building something similar and I thought that it's about time I chase that dream. This is when I decide that it's time to move on and so I joined them. Fast forward a couple of months and here we are, on my last day as a Traveloka employee.

Thank you Traveloka, for giving me the chance to get exposed more to the product side of things. You guys are the most critical tech crowd I've been in  and I'm proud to be one of the alumnee.

Now, it's time for a new adventure. The end of a journey is a beginning of a new one.

regards

-E-

follow @femmerling on twitter
visit my website

Monday, May 11, 2015

Everything Happens For A Reason

Everything happens for a reason. I know it sounds cliche but it's true. You may not realize what the reason is now. But there's a big chance that you'll know it later.
I've always dreamed of being a pilot as a kid. I grew up with that dream and took a good care of my eyes. When I was 18 and about to graduate from highschool, my Mother disapproves of my dream. So, I moved on and took computer science. One thing stayed. I always take a good care of my eyes, until this day.

I got married when I was 24, had my daughter when I was 25 and had my son when I was almost 27. Now I had a second daughter at 31. When my son was about 1 year old, we realized that something wasn't right with his right eye. We went to the doctor for diagnosis and teatment. The doctor said that we'd have to wait until he's 2 years old for futher treatment. The diagnosis was Strabismus.

When he was 2, we went to the ophthalmologist. He had his first pair of glasses because his right eye had a bad eyesight. That condition is impacting his left eye as well. We went for another check last weekend. This was about 2 years after the first check. His right eye condition was not getting any better. So he had his retina photographed. I could tell from the doctor's face that something was wrong. My son had Toxoplasmosis attack when he was still a fetus. It affected his right eye but he survived. That left a scar that prevented the propper nerves to form. The scar is near the center of his eyesight. This is why his right eye is not getting any better.

The doctor said that there is currently no cure for this condition. This is when I realized why I have a good pair of eyes. Anyone reading this please mark this promise I made to my self. I'll take a good care of my eyes until 2035. By that time I'll be 51 and have seen a lot of this world with my own eyes. By then, I'll be giving both of my eyes to my Son and took his eyes. He'll still have a lot of adventure by that time and I want him to see it with a better eye sight. I'm hoping that he'll be happy to see it through my eyes. I love you my son.



regards

-E-

Thursday, January 29, 2015

Android TDD Using JUnit, Robolectric and Mockito

Android now supports unit testing. Android unit testing runs on devices or emulators that adds extra time during development. I'm a big fan of TDD and the way android testing is done does not help me much.

However...

Thanks to Robolectric, headless testing is now possible by leveraging gradle. I wrote this post as a result of trying out several different approaches that confused me. Hopefully this one will help you set it up better.

How?

First, current common Android development projects are tightly coupled. Most stuffs are done in the Activity or Fragment, blame the tutorials. This makes it hard for us to actually do unit testing since a unit test should be isolated. The tight coupling makes unit testing impossible.

Then, come this approach called Model - View - Presenter (MVP). MVP aims at separating concerns.
The three components involved handles different concerns:


Model

This component groups all data related concerns. This component handles data queries (be it via SharedPreference or SQLite) and network connections. The Model will be the provider of data for the Presenter. The presenter will then sends the data to the View.


View

Just like the name suggests, the View handles all the presentation layers. You change the views, texts and contents in this component including navigation. The View should not handle view state and logic.


Presenter

This component handles the logic of the view and maintains the view state. The presenter will be the one communicating with the models and updates the view when data is retrieved.

The MVP components are created using interfaces that standardize it. This separates concerns from each layers. The components communicates via the interfaces and does not connect directly to the implementations. This removes tight coupling of each layers. You pose no effect to other layers when you subsitute your implementation.

For more references on MVP implementation try reading this blog post by Antonio Leiva.

Setting Unit Test on Android Studio Project

We need a special gradle plugin to set the environment for unit testing on Android. I use the Robojava gradle plugin by Gautam Korlam. It is simple and easy to set.

The first step you need to do is to create another module on your android project.


Make sure that you select the Java Library module.


After the module is created, delete all other files except the build.gradle so it looks like this


I named my library tests.

Now we need to tweak the gradle settings.

Make sure that your new library is listed in the settings.gradle file.
Mine looks like this:
include ':app', ':tests'
After that, we need to change the root build.gradle. That is the one on the root of your project.
Mine looks like this:


The next thing you need to change is the build.gradle of your main app. Make sure you list all the dependencies in this file and make sure that you set the test source to src/androidTest. Mine looks like this:


Then, finally you need to change the test module's build.gradle. This is to make sure that the test are executed in the right source and can be done headlessly. Mine looks like this:

And there you go, it's ready.

Anytime you wish to create a test, simply create a test on the presenter class, make sure it's a JUnit 4 test case and it's placed in the androidTest/ directory.

Anytime you wish to run the test go to the command line, cd to your project root folder and run:

$ ./gradlew test

If it is successful you should see something like this:


Robolectric tests can also be run for integration tests. You can also use this for continuous integration. Simply run:

$ ./gradlew build

Gradle will build and run tests. If any of the tests failed the build will fail.

I have the full example of this project on github. However, the project does not demonstrate the use of dependency injection as suggested by Antonio Leiva.

Feel free to comment or ask me.

regards

-E-

follow @femmerling on twitter
visit my website