Profile

Cover photo
Matthias Käppler
Works at SoundCloud
Attended Technical University of Kaiserslautern
Lives in Berlin, Germany
2,311 followers|453,536 views
AboutPosts

Stream

Matthias Käppler

Shared publicly  - 
 
Matthias Käppler originally shared:
 
My verdict for unit testing on Android: it's 2015, and it's still somewhat broken.

Perhaps not as broken as it used to be, but still broken in some really fundamental ways.

We've been using Robolectric 1 for a very long time in the SoundCloud app and built up a substantial test suite (cloc counts about 73K lines of test code), but building something that mission critical on legacy software is of course a ticking time bomb.

After all the recent fuss about improvements in Android unit testing, I spent quite some time evaluating the different approaches to select the one that would offer us the greatest benefit with the least amount of friction (side note: it's 2015--why does unit testing require time to make it work? It should be as straight forward as drinking a cup of coffee.) I have to say I left disappointed; some things are broken by design, others are just broken. Brief summary:

Variation 1: Running unit tests on a connected device
The obvious benefit here is one of confidence: you are instrumenting your code against an actual system image, with the same VM that will actually run your code in production. It's the real deal. In the past, this approach wasn't exactly a great solution for numerous reasons (poor emulator performance, impossible to use mocking libraries, no JUnit 4 support to name the biggest ones.)
This has gotten better: we have a JUnit 4 runner now [0], we have DexMaker (a bytecode backend for Dalvik) [1], and we have Genymotion, but one of the major problems still exists: the platform JAR is full of final classes and methods, so you either have to write your tests to take that into account, or move your code as far away from the platform as possible; which is likely a good idea anyway [2], but induces the cost of introducing abstractions that might purely exist for testability.

Variation 2a: Running unit tests on the JVM (not using Robolectric)
With the arrival of "experimental unit testing support" (now not experimental anymore), we can now run tests from src/test/java using ordinary test runners. Since it's an ordinary Java unit test, you can use ordinary test setups and libraries, too. Rejoice! However, this approach still has several drawbacks.
Although a Gradle task has been introduced that strips the platform JAR of all finals and method bodies, as soon as your test subject is somehow entangled with the platform, like when using Intents or Bundles, your test will likely fail, since all these classes are stubbed out. Since Intent or Bundle are foundational platform types, they typically don't appear as collaborators in constructors, so you either have to come up with awkward indirections ("intent providers") or, again, move your code as far away from the platform as possible (again, see [2]) You will also likely end up wiring a lot of mocks in your tests, making your tests hard to read and understand (after all, that's one reason why Robolectric was initially created)
A final annoyance: why on Earth am I not able to see both unit tests and acceptance tests at the same time? Due to some idiosyncratic behavior in either AS or Gradle's Android plugin, only one Gradle source set containing tests can be active at once, as chosen by the "test artifact" setting in your build flavors. So unit tests are piggy backed on a system that it wasn't really built for, and it means that any refactorings you apply to one source set will not apply to the other source set, which is just asking for trouble. I hope this is only temporary and will get addressed with future versions of the AS (I assume it's a shortcoming of AS.)

Variation 2b: Running unit tests on the JVM (using Robolectric)
After we tried so hard to move away from Robolectric 1, we closed the circle by opting for... Robolectric 3. At SoundCloud we decided it was the most preferable solution of the three. It comes with all the benefits of running a normal JUnit test, but doesn't penalize you for writing tests for classes that use things like Bundles directly. Unfortunately (--or fortunately?), the higher you go up in the layers, the more difficult it is (still) to unit test something, which is probably a signal that even with a powerful tool like Robolectric, you should test code that is close to the UI sparingly (if at all), and focus on testing presentation /logic/, business rules, and anything beneath. For instance, Robolectric hasn't quite figured out timing yet, so things like animations steered by a presenter might fail. [3] Overall it's a huge step forward from the initial release though, and comes nicely modularized. By combining test rules and base classes for your tests, you can also keep much of the setup boiler plate out of your actual test cases, so that you don't couple yourself too much to any RL specifics.

[0] http://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html
[1] https://github.com/crittercism/dexmaker
[2] https://blog.8thlight.com/uncle-bob/2014/05/11/FrameworkBound.html
[3] https://github.com/robolectric/robolectric/issues/1879
72
23
Stephane Schittly's profile photoGiorgos Kylafas's profile photoPaweł Marchewka's profile photoShintaro Katafuchi's profile photo
8 comments
 
+Matthias Käppler +Stephan Linzner could you please share on how we can mock Environment class and its methods? Because if we use Robolectric then test cases will run on JVM and hence it will not have any storage directory.
Add a comment...

Matthias Käppler

Shared publicly  - 
 
T-6 days!

More photos from Kelly, our amazing office manager who made it all happen:
http://kellyarobinson.com/portfolio/soundcloud/

Disclaimer: ping-pong table is still in the box, an obvious omission on the pictures ;-)
SoundCloud has released some sneak preview pics of its new office in the Factory ahead of the startup hub's official opening.
7
Federico Paolinelli's profile photoWalmyr Carvalho's profile photo
2 comments
 
Looks a great place to work! 
Add a comment...

Matthias Käppler

Shared publicly  - 
 
 
We’re thrilled to share that we've planted roots in the concrete jungle where dreams are made: our New York City office is officially open! Read all about it: http://blog.soundcloud.com/2014/06/03/soundcloud-new-york-city-office/
12
2
Stefan Hoth's profile photoLukasz Konieczny's profile photo
 
looks cool!
Add a comment...

Matthias Käppler

Shared publicly  - 
 
"RubyMotion 3.0 will support Android" http://feedly.com/e/W94siszS
reddit: the front page of the internet
3
Add a comment...

Matthias Käppler

Shared publicly  - 
 
"Google announces the first Android Test Lab in Paris" http://feedly.com/e/-DP-I6S6
Google announced that it would be building upon its partnership with NUMA (formerly named Silicon Sentier), an incubator, accelerator & overall communi
1
4
Mike Wolfson's profile photoKevin H.A. Tan's profile photo
Add a comment...

Matthias Käppler

Shared publicly  - 
 
 
Big +Google Maps update hits today 
Google Maps for iOS and Android is getting a big update today, bringing support for offline maps to both platforms, adding in lane guidance when driving, and integrating Uber as an option for...
1
Add a comment...
Have him in circles
2,311 people
Jeff Graham's profile photo
Toni Allcock's profile photo
Alex Revin's profile photo
Eric Engelking's profile photo
Paul Lammertsma's profile photo
Rajalakshmi Rajesh kanna's profile photo
Apurba Biswas's profile photo
Katherine Kuan's profile photo
swaroop J's profile photo

Matthias Käppler

Shared publicly  - 
 
 
Some of the best ideas are also the simplest. And there are few things more simple than SoundCloud, which in its seven year existence has sneakily become one of the best things online. How'd it get there? Slowly, surely, and with a cadre of artists as diverse as the internet itself.
6
Add a comment...

Matthias Käppler

Shared publicly  - 
 
 
Gradle Plugin 0.11.1 was just pushed. It should be available shortly depending on mirror replication.

release notes:

- Fix issue with artifact depending on android.jar artifact on MavenCentral. (this is the ApiVersion to Integer casting error)
- Fix issue with missing custom namespace declaration in generated manifest.
- Fix issue with validation of permission group in manifest merger.
2
1
Jesús Manzano Camino's profile photo
Add a comment...

Matthias Käppler

Shared publicly  - 
 
 
AboutLibraries
Just forget about the hard work to give credits. AboutLibraries does everything for you. Including the Activity or Fragment!

More information here:
http://mikepenz.github.io/AboutLibraries/

To the background:
Everyone (or at least many of us) always try to give credits to those people who create awesome libraries for us (so we don't have to get crazy, just to implement an easy function :D). But it was always very time consuming to copy and paste the required information, create a layout, manage the information, create an activity / fragment and include in your app.
With the time many of us stop to include those information in their apps because they just don't want to invest any time in it.
So i've created this lib. You can use it to just get the information (if you still want to build a custom activty) or you can just call the included activity and let the lib do all the hard work for you.
Right now just a few libs include the information file, and the lib itself also just includes a few information.

You can help and contribute by creating the information file for the libs you use and love. Create a pull-request and let the dev itself include it in his library (so it's even easier for you and everyone else to use) or if the lib isn't maintained anymore create a pull-request at the AboutLibraries repository so i can include it.

Enough words. Just check out the repository and have a nice evening and weekend! :D 
7
3
Marcos Trujillo's profile photoRalph H.M.'s profile photo
Add a comment...

Matthias Käppler

Shared publicly  - 
 
 
The Google I/O schedule is live, and our Android development tools talk will be streamed again, so hopefully you can all join us live on June 26th at 9am California time!

We're hoping to make the session both interesting and useful!

https://www.google.com/events/io/schedule/session/ac46ad42-19c0-e311-b297-00155d5066d7
Since its introduction last year, we\u0027ve added a lot of enhancements to Android Studio. In this session we will provide an in depth tour of the Android development tools and take a closer look at everything new \u002D along with tips and tricks for getting the most out of them!
5
1
Israel Ferrer Camacho's profile photo
Add a comment...

Matthias Käppler

Shared publicly  - 
 
 
Google Play services 4.4
A new version of Google Play services is rolling out to Android devices worldwide. This update includes new APIs as well as a number of new features to existing ones:

Street View and Indoor Maps - Embed Street View imagery into your app & extensions to Indoor Maps.

Activity Recognition - Two new activity detectors have been added to Location API: Running and Walking.

Mobile Ads - In-app promo ads enable users to directly buy virtual goods.

Wallet Fragments - Makes it extremely easy to add Google Wallet Instant Buy to an app.

You'll be able to get started with the new APIs as soon as the Google Play services rollout is complete -- a process we expect to take several days. We'll then release the updated Google Play services SDK and you'll be able to download it through the Android SDK manager. Watch for more information coming soon.

For more information, check out the link below:

Developer blog post: http://goo.gl/gjEfWq
A new release of Google Play services has begun rolling out worldwide, and as usual we have a number of features that can make your apps better than before.
2
1
Benoît `BoD` Lubek's profile photo
Add a comment...

Matthias Käppler

Shared publicly  - 
 
 
If you're interested in how the Android graphics system works (all of it), read this. #AndroidDev
6
1
theme ♥ music ♥ romantic - keane's profile photo
Add a comment...
People
Have him in circles
2,311 people
Jeff Graham's profile photo
Toni Allcock's profile photo
Alex Revin's profile photo
Eric Engelking's profile photo
Paul Lammertsma's profile photo
Rajalakshmi Rajesh kanna's profile photo
Apurba Biswas's profile photo
Katherine Kuan's profile photo
swaroop J's profile photo
Work
Occupation
Software Engineer
Employment
  • SoundCloud
    Software Engineer, 2013 - present
  • Qype
    Head Developer Mobile, 2009 - 2012
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Currently
Berlin, Germany
Previously
Hamburg, Germany - Roetgen, Germany - Kaiserslautern, Germany - Tokyo, Japan
Links
Contributor to
Story
Tagline
I, code.
Bragging rights
Survived a Bosnian wedding.
Education
  • Technical University of Kaiserslautern
    Computer Science, 2003 - 2008
Basic Information
Gender
Male
Other names
Mattes