android / android-test

An extensive framework for testing Android apps
https://android.github.io/android-test
Apache License 2.0
1.16k stars 314 forks source link

JUnit 5 support #224

Open matejdro opened 5 years ago

matejdro commented 5 years ago

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)

brettchabot commented 5 years ago

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.

matejdro commented 5 years ago

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.

TWiStErRob commented 5 years ago

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

mpeng3 commented 4 years ago

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.

olegivo commented 4 years ago

Any updates? Plans?

quentin23soleil commented 3 years ago

👋 Welcome to 2021. Could it be possible to be updated on this?

issamux commented 3 years ago

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

Luiz-Monad commented 3 years ago

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.

testifyqa commented 3 years ago

Would love native JUnit5 support, please make it happen

Apple-Flavor commented 2 years ago

welcome to 2022

serandel commented 2 years ago

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

mahozad commented 2 years ago

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

serandel commented 2 years ago

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

Moes81 commented 2 years ago

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.

TWiStErRob commented 2 years ago

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

OussamaHaff commented 2 years ago

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

JoseAlcerreca commented 2 years ago

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.

JoseAlcerreca commented 2 years ago

(@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.

TWiStErRob commented 2 years ago

@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.

dennisguse commented 2 years ago

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

JoseAlcerreca commented 2 years ago

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?

tfonteyn commented 2 years ago

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

jbduncan commented 2 years ago

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

@tfonteyn They do. :)

FibreFoX commented 2 years ago

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 1 year ago

Welcome to 2023. Any plans on adding this?

vinipazzini commented 1 year ago

Is it time?

azamattkhagalegov commented 1 year ago

Please add support JUnit5

PikalovPavel commented 1 year ago

April 2023, still waiting.

NebilHassen commented 1 year ago

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)

nasif02 commented 1 year ago

Its mid 2023. any update?

JoseAlcerreca commented 1 year ago

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.

CarmineLaface commented 1 year ago

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.

serandel commented 1 year ago

I've had success using https://github.com/mannodermaus/android-junit5.

GyulaJuhasz commented 10 months ago

Welcome to 2024.

erfansn commented 7 months ago

Hello to 1403

vincent-paing commented 1 month ago

One of the biggest advantage for us having Junit5 support is that we have a BFF written in Kotlin+Spring Boot. And it uses Junit 5. It's been a huge pain for us to do context switching between 4 and 5. We have a community plugin yes, but still it's missing feature like hilt injection, robolectric etc. Would be nice for Google to work on these extensions for us.