Recent posts

Reducing the deployment size of your JavaScript Azure Functions

January 12, 2020  1 minute read  

I’m doing some Azure Functions development in JavaScript at the moment, using the new azure-functions-core-tools. One of the features it has is command line publication, like this: $ func azure functionapp publish my-function-app I have a single function right now (called ping). Running the publish step creates a ZIP file: $ npx func azure functionapp publish my-function-app Getting site publishing info... Creating archive for current directory... Uploading 187.62 MB [##-...

Mocking Android resources with Mockito and Kotlin

January 03, 2020  3 minute read  

I bumped into an issue that was a little harder than I expected to solve, so this is the documentation. Requirement: Load a JSON file from the res/raw resource directory. Actually, that wasn’t the problem. The problem was how do you test that functionality? The library I have a basic configuration library that is constructed like this: class Configuration internal constructor(jsonContext: String): Map<String, Any> { internal constructor(stream: InputStream) : this(stream.buf...

Unit testing asynchronous Android network libraries

January 01, 2020  5 minute read  

I’m writing a network library for Android at the moment, and specifically looking at unit tests. In my last article, I looking at mocking the Android context and other Android specific libraries. Since I am writing a network client library, I need to go a step further and deal with the network connection itself. How can I test the asynchronous network calls in a repeatable manner? Fortunately, there’s a library for that. Square, the same people that brought you OkHttp, also produce a moc...

Two tips for unit testing Android libraries

December 24, 2019  3 minute read  

I’m busy writing a networking library for one of my Android apps. The question today is “how do I properly test the library?” There are a few problem areas, and I’ll cover two of them today. How do I properly mock classes that aren’t really Android specific, like android.location.Location and android.net.Uri? How do I properly mock the Android context? Android Studio already integrates the excellent JUnit packages for unit testing. I don’t want to have to write a visual app just to...

Build a better RecyclerView Adapter

December 13, 2019  3 minute read  

Many of my Android apps end up including listst, which are implemented via a RecyclerView. More importantly, I know all the items in the list ahead of time. Every single blog and tutorial always uses the same methodology. This ends up being a lot of boilerplate code. Create a view holder class Create a list adapter Attach the list adapter to the recyclerview Update the view holder class to implement the UI Check out the requirements around clicking Arrange for the list of item...