Skip to content

fada21/android-tdd-bootstrap

Repository files navigation

@Deprecated

Use google tools - refer to Google's android-testing

I wouldn't recommend using Robolectric. For unit test I'd use available JUnit support and for platform tests I'd go for Espresso.

android-tdd-bootstrap

##Goal:

  • TDD bootstrap Android project to be provided
  • Material design (using appcompat-v7) for preL devices to be enabled

I like TDD so I wanted to prepare bootstrap template for TDD. But hey - Android Lolipop is out with new material design. Thanks to appcompat library some features can be enabled to preL devices. I decided to give it a try and started digging.

##Guides:

##Libraries:

  • appcompat-v7 support lib (for material design)
  • robolectric - fast, runs on JVM, only hope for TDD
  • espresso - nice syntax, runs ui test on devices, slow
  • dagger - dependency injection framework

##How did it go?

Chris Banes posted some notes how to start using new support-v7 (here). I started from here and played with theming and new Toolbar widget (ActionBar killer wannabe). So I did very simple stub and proceed to building testing setup.

Testing was always painful in Android world. Let's just keep optimistic approach and get this done.

I decided to base my setup on deckard-gradle. It integrates Robolectric for TDD and Expresso for ui real device testing.

Want to see yourself?

  • git clone {github.repo}
  • ./gradlew clean test // for robolectric tests
  • ./gradlew clean connectedAndroidTest // for espresso tests

###Robolectric setup

Robolectric comes with nice gradle plugin. I defined a simple failing test. It failed. Hurray. Then added new and expected test succeeding. My optimism ended. Robolectric doesn't play nice with Appcompat theming. Also it doesn't support just yet Toolbar widget nor Cardview. That's the way Robolectric works. It has to provide own implementation to Android classes. So when new Android features are released there's always a lag. Problems with appcompat theming are already reported to robolectric team and on stackoverflow.

O well. No Robolectric for appcompat. Still I can write some unit tests only for logic but I don't need Robolectric for that. Example how to do jUnit setup here.

I tried also to integate tests into Android Studio. No success. Involves manual IDEA files editing, still not working, I gave up.

Ok. Maybe I won't be able to do TDD sor some while until it will be fixed. (still we can leave our projects and rush to robolectric development, that's open source after all).

Robolectric summary:

  • doesn't play well with appcompat, at all issue and stackoverflow
  • supports only Android APIs 16, 17 and 18
  • it lags behind KitKat and now Lolipop
  • integrating with Android Studio is too painful
  • fast when working

###Let's try Espresso

Not without problems but it worked. Unfortunately had some issues when provided updated versions of dependency libraries. E.g. needed fallback from Dagger 1.2.1 to 1.1.0. Also it has some problems when running on KitKat and Lolipop devices described here. I observed also some test to fail not deterministically on this devices but had no time nor energy to chase that.

Espresso summary:

  • nice DSL
  • fast UI testing
  • backed by Google

##Conclusion

I was not very successful (in terms of using appcompat-v7:21). My TDD attempt with Android failed. Hopefully it will get to work eventually. Espresso test was working but still I had to many issues on the way to recommend that.

##Next?

I'm thinking of using just plain jUnit and TDD only logic. I'm thinking about giving a try to Robotium.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages