DEV Community

Discussion on: My First Unit Test

Collapse
 
andy profile image
Andy Zhao (he/him)

Great post! It feels great to automate something and save a ton of time doing it.

Test writing was a pain for me to begin with though, it really is like writing in another language. At least Ruby tests are like that anyway. What'd you think of the learning part of writing tests? Interested to hear your perspective on writing tests for Android/Java.

Collapse
 
s_anastasov profile image
Stojan Anastasov

When I first started developing, testing on Android sucked. The testing support was ActivityInstrumentationTestCase and ActivityInstrumentationTestCase2 both deprecated now - which means they fucked up twice :D. All test used to run on the emulator. On top of that I didn't have any experience with testing.

As I mentioned in my article since Android Studio 1.1 testing support was improved. We can run unit test on our computers if we don't have Android dependencies.

Of course to write unit test, first you need to write testable code. We have libraries for dependency injection like dagger and dagger2. We have the same tools as in java: junit and Mokito.

For UI tests we have Espresso. Android studio can record our interactions with the app and write tests code for us.

In the last Google I/O we got a few new Architecture components which help us build our app in a more modular and testable way.

As the testing support in the platform grow, my testing skills also get better and I write more tests. I still not at a place where I want to be, but I am getting there.