mannodermaus / android-junit5

Testing with JUnit 5 for Android.
Apache License 2.0
859 stars 52 forks source link

Invalid test names for repeated and parametrized tests #317

Closed olga999999 closed 5 months ago

olga999999 commented 5 months ago

Information about the test's parameter and repetition is not included in the test name when tests are executed not as a whole test class/suite, but separately, one by one. This leads to the automatically generated logcat logs having the same filename and therefore being overwritten on each repetition/parameter. E.g. on the screenshot below the whole test suite is executed. Test names contain the information about repetitions and parameters.

image

Here only one test is executed at a time. No information about repetitions and parameters.

image image
mannodermaus commented 5 months ago

Hey, thanks for reporting. I can't confirm that this is what I see on my end, the output is identical whether I execute the entire instrumentation test suite or a single class. 🤔

Single Suite
single suite

May I ask what version of JUnit 5, the android-junit5 plugin and its instrumentation libraries you are using in your project? It's possible that a recent unreleased change has improved something that hasn't been publicized yet.

olga999999 commented 5 months ago

Hey, thanks for reporting. I can't confirm that this is what I see on my end, the output is identical whether I execute the entire instrumentation test suite or a single class. 🤔

Sorry for my bad explanation. If you execute a whole class, the issue won't appear. Can you try executing only repeatedTestExample or only parametrizedTestExample?

mannodermaus commented 5 months ago

Thank you for the quick response and explanation! No worries, I was the one who read it wrong – "only one test" was referring to a single test method, not a single test class. With this cleared up, I can reproduce this on my end as well:

Screenshot 2024-04-10 at 9 16 24

Having identical test names could create other problems down the line, so this is definitely something that needs fixing. Thanks for reporting!

mannodermaus commented 5 months ago

Good news! I narrowed down the cause for this to some special case handling inside the test tree generator. Unfortunately, I cannot simply remove this safeguard, as it would break other single-method executions from the IDE (such as #199 and #207, which were the original motivation for adding this). The reason is a limitation in how the Android instrumentation expects its classic tests to be named. This restriction doesn't seem to apply to all kinds of tests though, so I may have an approach in the works. Stay tuned for more.

Edit: We've got it. 💪

Screenshot 2024-04-10 at 20 25 11
mannodermaus commented 5 months ago

This will be released alongside the upcoming instrumentation test libraries 1.5.0! If you need the fix now, you can use the 1.5.0-SNAPSHOT in the meantime. 🙇‍♂️

olga999999 commented 5 months ago

This will be released alongside the upcoming instrumentation test libraries 1.5.0! If you need the fix now, you can use the 1.5.0-SNAPSHOT in the meantime.

Thank you so much!

olga999999 commented 5 months ago

Sorry for bothering you again, but it looks like SNAPSHOT version is not available on maven.

mannodermaus commented 5 months ago

Not on Maven Central anyway, that's correct. You'd need to grab them from their snapshots repository by adding the following repository to your project:

repositories {
  // mavenCentral(), google(), whichever other repositories you have, are here already...
  // Then please add this one
  maven { setUrl("https://oss.sonatype.org/content/repositories/snapshots/") }
}

Sorry, I usually add this to my comments when resolving tickets, but forgot this time. 🙈