Jul 31Testing Key-Press Events in RobolectricLet’s say you need write a unit test for key-press events in Android. You want to test how a widget behaves when it receives certain key-press events, like in an EditText. To illustrate, let’s say you have an EditText that takes in an order number, but you want the order…Robolectric5 min read
Jan 23Comparing BigDecimals for EqualityI had some code that subtracted two BigDecimal numbers in Kotlin (the JVM version of Kotlin, that is), and I needed to check if the result was zero to avoid a divide-by-zero error. To do that, I tried simply comparing the result of the subtraction to a BigDecimal number with…Kotlin3 min read
Dec 18, 2021Getting a Fully-Expanded RecyclerView to Scroll With Other Content On the PageLet us say you have a view that has some content at the top (which we will call the header), followed by a RecyclerView at the bottom. And you want both to scroll together as one, so when you scroll the page up, the header scrolls up with the RecyclerView…Recyclerview2 min read
Dec 12, 2021Testing Delayed Tasks in RobolectricLet’s say you need to test an update to your user interface after a time delay. For example, a filter bar. You enter text in the filter bar, and it will filter out items below that match that particular term. The filter happens after you change the text, so you…Robolectric2 min read
Dec 12, 2021Fixing Sign-in Issues with Guest WiFi on AndroidI was recently at a hotel, and was trying to connect to their WiFi. When I first connected from my Android tablet it asked me to Sign-in to the network, so I did that, and got in. Later on, I had to connect again, which I did, and was not…Android1 min read
Dec 12, 2021isChecked vs. isSelected for Android CheckBoxes and RadioButtonsJust wanted to point out a mistake I’ve sometimes made. When working with CheckBoxes and RadioButtons, I’ve often made the mistake of calling isSelected() on them if I want to know whether its button has been “checked” or “pushed in”. // I'm thinking this actually checks that the radio button…Android App Development3 min read
Dec 12, 2021Testing Dialogs in RobolectricWhen you test a View/Fragment/Activity in Robolectric, you may end up wanting to test whether a Dialog shows up at the right time, verify its contents, and test interactions with the Dialog. For example, you may want to test that a confirmation dialog comes up when you click a “Delete”…Robolectric3 min read
Dec 8, 2021Debugging Android Unit Tests from the Gradle Command LineNormally, when you need to debug an Android unit test you would do it from Android Studio. You can set breakpoints in there easily and then run the test in debug mode.Gradle4 min read
Dec 7, 2021Adding Android Studio to your Applications Launcher and Favorites Bar in UbuntuI use Android Studio on my Ubuntu laptop. And on UNIX systems, the Android Studio installation is simply a tarball file that you unpack to a particular directory. To run it, you run the shell script <install-location>/android-studio/bin/studio.sh . Well that’s nice, but I would rather have it be an icon…Ubuntu4 min read
Oct 10, 2021Robolectric Tips: Testing RecyclerViewsHow to get ViewHolders to render in RecyclerViews when testing in Robolectric Like most other Views in Android, RecyclerViews can also be tested in Robolectric. For example, you can verify the contents of their ViewHolders and test interactions with them such as clicks. However if you simply try to launch the Activity or Fragment that contains the RecyclerView and set up its…Robolectric3 min read