DEV Community

Cover image for Matt's Tidbits #65 - It's time for proper support for JUnit 5

Matt's Tidbits #65 - It's time for proper support for JUnit 5

mpeng3 profile image Matthew Groves Originally published at Medium ・2 min read

Last time I wrote about an interesting Hamcrest error and how I resolved it. This week, I have a quick story about writing JUnit 5 tests for Android apps.

Recently I started writing a new software library, and as such, wanted to make sure I was using all of the latest tools so my code didn't take on technical debt from the beginning.

If you've read my blog for any period of time, you know I'm a huge proponent of testing, so naturally, I wanted to make sure that my new library was extensively unit-tested and was built on the latest versions of testing tools.

I did a little Google searching and found that there's a new version of JUnit -  JUnit 5, that brings a refined API and powerful features, so naturally I wanted to use it.

It's fairly easy to set up, so I was pretty quickly off and writing unit tests with the new framework.

... That is, until I tried to run the tests. It's easy to run them within Android Studio - you can just run them as you've run other unit tests. But, when it comes to running them from the command line via Gradle (or in your CI tool), nothing happens.

Doing a little more digging, I found that most people use a 3rd-party plugin to allow the Android Gradle Plugin to run JUnit 5 tests:

Somehow, despite JUnit 5 being released over 2.5 years ago, Android Studio still doesn't have proper support for it. I even found this issue filed against the AndroidX Test library over a year ago:

After considering all of these factors, I decided to go back to JUnit 4 instead of using JUnit 5, because I don't want to be reliant on a 3rd-party library for running unit tests.

If you'd like to see native JUnit 5 support, please go like and/or comment on the Android-Test issue linked above - perhaps with more community outcry we can get this prioritized!

What version of JUnit are you using on your project? If you have switched to JUnit 5, what has your experience been like? Let me know in the comments! And, please follow me on Medium if you're interested in being notified of future tidbits.

This tidbit was originally delivered on March 27, 2020.


Editor guide