Test method naming conventions

157 views
Skip to first unread message

pshm...@chromium.org

unread,
Oct 4, 2018, 9:58:32 AM10/4/18
to java
Hi. I'd like to propose the following changes to the way test methods are named:

1) Drop the "test" prefix. Test methods have @Test annotation, while the "test" prefix is not required and adds nothing to the meaning.

2) Use underscores to improve readability of long test method names.
Ideally each test method should test only one scenario, and its name should describe that scenario. The side effect of that is long method names, such as canShowControlsAfterTheOnlyHidingTokenRemoved. Using underscores to split the name into logical parts makes it a bit more readable: canShowControls_AfterTheOnlyHidingTokenRemoved. This practice is widespread in the Android community and is even used in the official docs: https://developer.android.com/training/testing/unit-testing/local-unit-tests#java

John Budorick

unread,
Oct 4, 2018, 10:05:24 AM10/4/18
to pshm...@chromium.org, ja...@chromium.org
Beware that our test runner still expects test methods to be prefixed with "test" (here and here) and would need to be updated before proceeding with proposal 1.

--
You received this message because you are subscribed to the Google Groups "java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java+uns...@chromium.org.
To post to this group, send email to ja...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/java/05a50286-11f2-4466-b8bb-0935d99df93f%40chromium.org.

Pavel Shmakov

unread,
Oct 4, 2018, 11:01:54 AM10/4/18
to jbud...@chromium.org, ja...@chromium.org
Hm, I see instrumentation tests without "test" prefix being run, both locally and in tryjobs. See for example http://crrev.com/c/1226595, TrustedWebActivityClientTest.java

John Budorick

unread,
Oct 9, 2018, 4:37:55 PM10/9/18
to pshm...@chromium.org, ja...@chromium.org
Ah, yeah, I stand corrected. Some of our runners support listing by invoking the instrumentation (rather than by parsing the dex or the jar), and that supports @Tests that don't start with "test".

Reply all
Reply to author
Forward
0 new messages