JUnit5 in an Android Project

efe budak
4 min readFeb 12, 2023

When you create a new android project junit4 is the dependency you get automatically. However, JUnit5 is the next generation of JUnit so why not migrate the default JUnit4 dependency to the shiny new JUnit5 one? Then we can have a look at some of the fancy features of JUnit5.

Note: I’ll only focus on the migration of a newly created application. If you have a project that already has JUnit4 tests then you’d have more steps to fully migrate to JUnit5.

Photo by Julia Craice on Unsplash

JUnit5 migration from JUnit4

Since we don’t have any test in a newly created android application (other than the assertEquals(4, 2 + 2) example test) we can go ahead and change the dependency to testImplementation(“org.junit.jupiter:junit-jupiter:5.9.2”) .

build.gradle(:app)

When we synch the Gradle we’ll able to replace the @Test annotation and assert imports.

However, after removing the old imports and trying to run the test it’ll fail with the following error.

--

--

efe budak
efe budak

Responses (1)