android/android-test

JUnit 5 support

matejdro opened this issue ยท 35 comments

JUnit4 is the old JUnit system that was last updated way back in 2014. JUnit5 brings many new improvements, but at the moment it is tough to use it on Android.

There is 3rd party gradle plugin that supports JUnit5: https://github.com/mannodermaus/android-junit5 and while it works fine, it especially lacks in UI rules like in ActivityRule or ServiceRule (All official rules are for JUnit4, so they have to be rewritten if one wants to use JUnit5 for instrumentation tests).

(Copied from https://issuetracker.google.com/issues/127100532)

Thanks for the report.

We have JUnit5 support on our roadmap, but to be honest its not a super high priority at the moment in comparison to other features.

However, we have been thinking about JUnit5 and other test frameworks when planning future APIs. In general, we're trying to make new APIs test-framework agnostic by default. For example: androidx.test.core.ActivityScenario exists as a 'core' API without any JUnit dependencies. All the meaty logic for testing Activities is contained within this API, which will be officially replacing ActivityTestRule in a future release.

The hope is then that in the future, it would be easier for us or contributors to create simple wrappers for test framework specific extensions. Like we've done for JUnit4 in androidx.test.ext.junit.rule.ActivityScenarioRule.

I haven't used JUnit5 much myself but from brief reading it looks like 'extensions' are the equivalent to Junit4 Rules? So for example, someone could hopefully easily create a JUnit5 ActivityScenarioExtension that calls launch() and close() before and after each test.

I haven't used JUnit5 much myself but from brief reading it looks like 'extensions' are the equivalent to Junit4 Rules? So for example, someone could hopefully easily create a JUnit5 ActivityScenarioExtension that calls launch() and close() before and after each test.

Yes, exactly.

was last updated way back in 2014

Mind you that JUnit 4.13 is almost released, but I agree Jupiter is way more awesome.

someone could hopefully easily create

it would be nice to have first party support, if it's so easy I don't see why not

Any update on a timeline for official JUnit 5 support? This really seems like something that should be supported natively without the need for a 3rd-party plugin.

Any updates? Plans?

๐Ÿ‘‹ Welcome to 2021. Could it be possible to be updated on this?

Any native/official JUnit 5 support for Android (no 3rd part library) ????

You don't seem to have the resources to that massive scope of supporting all possible testing frameworks.
Why don't you just add support for JUnit5 and make it de-facto the testing, and ignore the others, no use uses them anyway, or they can pigback on the JUnit5 executing engine. Every developer end up having their own hacked copy of a bridge to allow JUnit5 tests to run on top of the JUnit4.
JUnitEngine5 was created precisely to solve your problems, creating another abstraction on top of it seems excessive, and that's why for 4 years, and nothing.

Anyway, I'm migrating to KoTest, so it doesn't matter anymore, as mannordemaus binding is enough to make the basics of JUnit5 run.

Would love native JUnit5 support, please make it happen

welcome to 2022

Come on, Google, you only had THREE years to implement this.

Here is a related Stack Overflow post: JUnit 5 for Android testing

Thanks, I got it working. But it would be cool to not need an additional plug-in for this...

I hear the following sentence almost every year on Google I/O: "We listen to our developers!". Well, I would really like Google to listen to us on this one.

(@brettchabot, just in case, please look at this query when prioritizing based on community feedback.)

I hope that testing on Android will get one day the same love as Compose and all other opinionated architectural guides...

JUnit5 support has been in the roadmap since its release, but our developer surveys consistently rank this below other features to invest in, such as testing support in Compose, Gradle Managed Devices or Automated Test Devices.

We appreciate the feedback and we're aware some developers feel very strongly about this (in favor and against) but please remember to keep the discussion respectful and helpful.

(@brettchabot, just in case, please look at this query when prioritizing based on community feedback.)

Thanks, the team is aware and it's why it's in the roadmap.

@JoseAlcerreca are those "other" features also the same team as the one that works on Espresso/JUnit runner? I would have thought that Compose testing is Compose UI team's responsibility, GMD is part of AGP, and ATD is done by a team that deals with Android SDK and emulators.

@JoseAlcerreca What can we do to make this happen?
Do you need engineering support?

are those "other" features also the same team as the one that works on Espresso/JUnit runner?

Yes, the testing team is involved one way or another in all those projects.

it would be nice to have first party support, if it's so easy I don't see why not

To clarify this, Brett was referring to the creation of an ActivityScenarioExtension, not talking about a full migration to JUnit5. This would be a non-trivial undertaking, including years of releasing and maintaining junit4 and junit5 artifacts, starting with the runner and dealing with API breakages.

I haven't used the 3p gradle plugin. It looks like it only works on API 26 and newer. Are there any other limitations?

weird... my comment was deleted - trying again: maybe google developers don't test themselves?

weird... my comment was deleted - trying again: maybe google developers don't test themselves?

@tfonteyn They do. :)

So this issue is open for over 3 years now .... is there any way to see what priority JUnit 5 support actually has? Right now I am not being able to even guess when this might be available.

tagirf commented

Welcome to 2023. Any plans on adding this?

Is it time?

Please add support JUnit5

April 2023, still waiting.

Does anybody know if jetpack Compose has an offical statement about current situation with JUnit5 (or anyhwere that states that they currently dont support JUnit5)

Its mid 2023. any update?

Does anybody know if jetpack Compose has an offical statement about current situation with JUnit5 (or anyhwere that states that they currently dont support JUnit5)

The ComposeTestRule is a JUnit4 rule. There's no support for JUnit5.

Does anybody know if jetpack Compose has an offical statement about current situation with JUnit5 (or anyhwere that states that they currently dont support JUnit5)

The ComposeTestRule is a JUnit4 rule. There's no support for JUnit5.

But I guess you test compose only in jvm, there you can use the test framework you prefer.

Welcome to 2024.

Hello to 1403