[Bug]: Excessive underscores in test function names
Is there an existing issue for this?
- [X] I have searched the existing issues
Is there a StackOverflow question about this issue?
- [X] I have searched StackOverflow
What happened?
For example, in https://github.com/android/nowinandroid/blob/607c24e7f7399942e278af663ea4ad350e5bbc3a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepositoryTest.kt
Check all codebase and use maximum of 2 underscores per test in the format: given_when_then
Relevant logcat output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
I can take this
@dturner I am struggle with some decision
-
ForYouViewModel
Original test naming is expect_condition, like
stateIsLoadingWhenFollowedTopicsAreLoading, I don't understand the reason, but I prefer using direct statement likewhenFollowedTopicsAreLoading_thenStateIsLoading -
ListToMapMigration, IntToStringMigration
I never heard naming convention in test start with capitalize, I would like to change
ListToMapMigration_should_migrate_bookmarksintolistToMapMigration_shouldMigrateBookmarks -
NewsResourceDaoTest
newsResourceDao_filters_items_by_topic_ids_or_author_ids_by_descending_publish_datetest with long condition expression would looks likenewsResourceDao_filtersItemsByTopicIdsOrAuthorIdsByDescendingPublishDate, but this change doesn't make the name more readable -
NewsResourceTypeConverterTest
Not sure the object in test naming, the original version
test_room_news_resource_type_converter_for_video, althoughtestRoomNewsResourceTypeConverter_toVideowill be more straightforward, however the change fromfortotomeans different object in sentence
any advice?
I think that looks fine @Kenny50
This could be a lint 🤓 and pretty easy to write too. But I'm not sure if this would fit in such a "app architecture showcase" repository. An other simpler solution is to simply use Kotlin's backticks for method names and use spaces.
@Test
fun `given X when Y then Y`()
@dturner let us know what's the best approach here.
Although, there already is a DesignSystemDetector custom lint, so, this might not be a bad idea to add one for test method conventions after all?
I seem to remember there was some issue which prevented us using backticks for test names.
@JoseAlcerreca Any thoughts?
Backticks will not work on Android instrumented tests, but they work fine on regular unit tests.