DEV Community


Discussion on: How to write tests for an android app?

subbramanil profile image
Subbu Lakshmanan • Edited

Hey Buddy,

First of all, Don't doubt yourself as a developer just because you haven't written test cases yet. IMO not many people start their career writing test cases for each of their projects. Most of them start their testing the app by hand as you did. I did the same thing when I started. Although JUnit test cases are available for quite a long time, I haven't used them in my initial projects. It took some time for me to understand the concepts, practice and implement in my projects. i.e., how to write proper test cases.

Writing test cases differs from project to projects. Some people would be perfectly happy with no test cases on their personal projects since there's nobody to enforce them. Some people religiously write test cases in their personal projects, since it may be the only opportunity to learn and apply testing concepts.

Also, you would be surprised by how many apps & services running in the real world without enough test cases. Most people won't accept, but in my experience, I have seen projects that don't have a single test case running successfully in the real world for a number of years.

I'm not advocating here, it's okay not to write test cases. I'm just saying don't beat yourself up since it's a new concept to you. Also don't be afraid to take the first steps into writing test cases. Initially, it will suck, but over time you will gain an understanding of having good test cases.

Initially, you may not understand why to write a test case that you know for sure it will work. And probably much easier to test by re-running the code. That's where most people stop. IMO, the value of test cases comes when you try to refactor the code. Running the test cases will give you confidence that you didn't introduce any new bugs.

You can find a number of articles on Android Testing. And you can browse through the Google GitHub sample projects to understand how to do.

I have browsed through your code, ran it on the simulator. Your code looks pretty neat. Kudos to you!! One thing I can recommend is to review the Android lint warnings.

In Android Studio, you can see all the lint warnings from the menu Analyze --> Inspect Code.

Also, your app gave me a good idea for one of my side-projects. As thanks, I have submitted a PR. Check it out.

Forem Open with the Forem app