-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create TestMethodDetector
Lint to detect common naming patterns we want to avoid
#899
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Simon, can you solve the conflicts please? Thanks!
69207ee
to
72e0a70
Compare
Hopefully these 3 new Lint checks makes sense for this repository. |
🛎️ Ping |
🛎️ Ping 🥺 |
lint/src/main/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetector.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool. Thanks for adding, and sorry for the delay in reviewing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was a bit quick to approve there. Looking a bit more closely, the UNDERSCORE
check isn't valid.
We want tests follow this format: given_when_then
where given
, when
and then
are in camel case e.g. uiState_whenFollowedTopicsAreLoading_thenShowLoading
.
What we don't want is for underscores to be used to replace spaces between words e.g. network_news_resource_can_be_mapped_to_news_resource_entity
or for no underscores to be used e.g. deepLinkedNewsResourceIsFetchedAndResetAfterViewing
I'm not sure if it's possible to create lint checks for this. Or whether it'd be simpler to just rename the existing tests which don't follow the format.
We can definitely enforce this through Lint checks. We simply need to find the right regex. So what you actually want is something like: |
Looking through some of the test, the clearest test names seem to be those that follow these formats:
In which case the format should be:
My regex isn't great but I think it's: Here's some methods which will require a rename:
I haven't had a chance to look through all the tests to see whether there are other cases which don't fit this format. Feedback or other suggestions welcome. |
6a5b24b
to
1c5323c
Compare
1c5323c
to
4732249
Compare
The detector has been updated to conform to your specs: |
Change-Id: Iec1d07787a6e1cd350b9d8d082e729ef62492013
lint/src/main/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodNameDetector.kt
Outdated
Show resolved
Hide resolved
lint/src/main/kotlin/com/google/samples/apps/nowinandroid/lint/NiaIssueRegistry.kt
Outdated
Show resolved
Hide resolved
…/NiaIssueRegistry.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bearing with me on this one. I've never written a lint check so it took me a while to figure out whether this was the correct approach.
No worries. |
This will need to be applied on top of this PR to run correctly on all modules:
Closes #345