Style guide clarification for unit test naming

790 views
Skip to first unread message

Dominic Farolino

unread,
Jul 2, 2021, 3:16:49 PM7/2/21
to cxx, Alexander Timin, Shivani Sharma
In Chromium we often use the `_unittest.cc` suffix to distinguish unit tests from browser tests (typically in `_browsertest.cc` files).

However, the Google C++ style guide mentions that the `_unittest.cc` suffix for unit tests is deprecated, and the more-general `_test.cc` suffix should be used instead. Using `_test.cc` in Chromium can still distinguish unit tests from browser tests, although it is a lot less explicit in general, so I'm wondering what the Chromium-specific guidance here should be? I don't have a strong opinion, but most people I've talked to seems to still prefer using `_unittest.cc` to distinguish unit tests from browser tests, which makes sense to me. Regardless, I'd like to know:
  • What others think about this
  • If we decide to keep using `_unittest.cc`, is it worth adding something to the Chromium C++ style guide to clarify our divergence from the Google C++ style guide? I think so
Separately, there are many more instances of `_test.cc` in Blink than there are `_unittest.cc`, but this is suspected to be a holdover from the WebKit days. We have a separate style guide specifically for Blink, but I'd prefer having Blink and Chromium in general be aligned on whatever stance we take here. I suspect we'll resolve to using `_unittest.cc` suffixes, in which case it would make sense to leave the Blink style guide alone and I suppose rename all of the `_test.cc` files in Blink to use the `_unittest.cc` suffix. Do people have any thoughts on this?

Thanks,
Dom

dan...@chromium.org

unread,
Jul 2, 2021, 3:18:43 PM7/2/21
to Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
I would like to avoid investing any engineer effort in renaming our unit test files, so I would suggest we stick with _unittest everywhere for consistency. Blink has been slowly moving toward consistency with the rest of Chrome already I believe.

Adding this to our style guide seems appropriate.
 

Thanks,
Dom

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAP-uykB0woMo0bqnD2Y0Eo8Ck-LitgaMhMFMZr%3DpHsq31WxZEQ%40mail.gmail.com.

Peter Kasting

unread,
Jul 2, 2021, 3:26:04 PM7/2/21
to Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
I'd like to avoid diverging from Google style on this, but I'd like even more not to say anything in the styleguide about something so trivial.  So, my preference is "name new files _test.cc, don't rename existing files, don't write anything in the styleguide, don't stress about violations".

PK

--

dan...@chromium.org

unread,
Jul 2, 2021, 3:38:34 PM7/2/21
to Peter Kasting, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
On Fri, Jul 2, 2021 at 3:26 PM 'Peter Kasting' via cxx <c...@chromium.org> wrote:
I'd like to avoid diverging from Google style on this, but I'd like even more not to say anything in the styleguide about something so trivial.  So, my preference is "name new files _test.cc, don't rename existing files, don't write anything in the styleguide, don't stress about violations".

The style guide does not mention browsertests but it does mention `_regtest`, and my reading of it would say that we should not use our browsertest suffix either then. Since we presumably want to keep that prefix and distinction (I think this is a key property of our testing systems and strategies), I think we should keep both. From there, stating this defacto rule somewhere in the guide does seem worthwhile to me, as it currently is left up to institutional knowledge, and noticing and copying existing code.
 

PK

On Fri, Jul 2, 2021 at 12:16 PM Dominic Farolino <d...@chromium.org> wrote:
In Chromium we often use the `_unittest.cc` suffix to distinguish unit tests from browser tests (typically in `_browsertest.cc` files).

However, the Google C++ style guide mentions that the `_unittest.cc` suffix for unit tests is deprecated, and the more-general `_test.cc` suffix should be used instead. Using `_test.cc` in Chromium can still distinguish unit tests from browser tests, although it is a lot less explicit in general, so I'm wondering what the Chromium-specific guidance here should be? I don't have a strong opinion, but most people I've talked to seems to still prefer using `_unittest.cc` to distinguish unit tests from browser tests, which makes sense to me. Regardless, I'd like to know:
  • What others think about this
  • If we decide to keep using `_unittest.cc`, is it worth adding something to the Chromium C++ style guide to clarify our divergence from the Google C++ style guide? I think so
Separately, there are many more instances of `_test.cc` in Blink than there are `_unittest.cc`, but this is suspected to be a holdover from the WebKit days. We have a separate style guide specifically for Blink, but I'd prefer having Blink and Chromium in general be aligned on whatever stance we take here. I suspect we'll resolve to using `_unittest.cc` suffixes, in which case it would make sense to leave the Blink style guide alone and I suppose rename all of the `_test.cc` files in Blink to use the `_unittest.cc` suffix. Do people have any thoughts on this?

Thanks,
Dom

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAP-uykB0woMo0bqnD2Y0Eo8Ck-LitgaMhMFMZr%3DpHsq31WxZEQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.

Dominic Farolino

unread,
Jul 2, 2021, 3:46:43 PM7/2/21
to dan...@chromium.org, Peter Kasting, cxx, Alexander Timin, Shivani Sharma
On Fri, Jul 2, 2021 at 1:38 PM <dan...@chromium.org> wrote:
On Fri, Jul 2, 2021 at 3:26 PM 'Peter Kasting' via cxx <c...@chromium.org> wrote:
I'd like to avoid diverging from Google style on this, but I'd like even more not to say anything in the styleguide about something so trivial.  So, my preference is "name new files _test.cc, don't rename existing files, don't write anything in the styleguide, don't stress about violations".

The style guide does not mention browsertests but it does mention `_regtest`, and my reading of it would say that we should not use our browsertest suffix either then. Since we presumably want to keep that prefix and distinction (I think this is a key property of our testing systems and strategies), I think we should keep both. From there, stating this defacto rule somewhere in the guide does seem worthwhile to me, as it currently is left up to institutional knowledge, and noticing and copying existing code.

I think I agree with Dana here. I've uploaded a small CL to clarify this in the style guide, but I'm happy to hear any more objections or opinions.

K. Moon

unread,
Jul 2, 2021, 4:34:56 PM7/2/21
to Dominic Farolino, danakj chromium, Peter Kasting, cxx, Alexander Timin, Shivani Sharma
This should be pretty easy to enforce with a presubmit check, right?

dan...@chromium.org

unread,
Jul 2, 2021, 4:57:17 PM7/2/21
to K. Moon, Dominic Farolino, Peter Kasting, cxx, Alexander Timin, Shivani Sharma
On Fri, Jul 2, 2021 at 4:35 PM K. Moon <km...@chromium.org> wrote:
This should be pretty easy to enforce with a presubmit check, right?

What are we enforcing? That browser tests and unittests are properly distinguished?
 

K. Moon

unread,
Jul 2, 2021, 4:58:29 PM7/2/21
to danakj chromium, Dominic Farolino, Peter Kasting, cxx, Alexander Timin, Shivani Sharma
Use of _unittest or _browsertest instead of just _test.

dan...@chromium.org

unread,
Jul 2, 2021, 5:09:36 PM7/2/21
to K. Moon, Dominic Farolino, Peter Kasting, cxx, Alexander Timin, Shivani Sharma
On Fri, Jul 2, 2021 at 4:58 PM K. Moon <km...@chromium.org> wrote:
Use of _unittest or _browsertest instead of just _test.

Ah ok, thanks. Yes we could, though it would prevent test helpers from ending in _test as well. Like these: https://source.chromium.org/search?ss=chromium%2Fchromium%2Fsrc&q=for_test.h

Peter Kasting

unread,
Jul 2, 2021, 6:09:04 PM7/2/21
to Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
I don't want to keep _browsertest.cc either.

PK

dan...@chromium.org

unread,
Jul 2, 2021, 6:50:05 PM7/2/21
to Peter Kasting, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
I think that's a rather large change to make at this point, for no reason that I see other than because Google did it. That's a tough sell to me, but regardless, if we're going to make a change like that, probably cxx@ is not the place to decide.

Peter Kasting

unread,
Jul 2, 2021, 7:47:31 PM7/2/21
to Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
The change would simply be not naming things that in the future, because doing so is deprecated. There's no need to rename existing files. As for why do so -- it's easier to find test code when it's always named the same, and it would save on renames when moving code between test suites (as had bitten me repeatedly before).

PK

Avi Drissman

unread,
Jul 2, 2021, 10:09:54 PM7/2/21
to Peter Kasting, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
For classes that have both unittests and browsertests, what would be the suggested file naming?

Peter Kasting

unread,
Jul 2, 2021, 11:17:22 PM7/2/21
to Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
I don't know, how does google3 deal with multiple kinds of tests?

PK

Peter Kasting

unread,
Jul 4, 2021, 12:32:22 PM7/4/21
to Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
On Fri, Jul 2, 2021 at 8:17 PM Peter Kasting <pkas...@google.com> wrote:
I don't know, how does google3 deal with multiple kinds of tests?

(Maybe we could #ifdef UNIT_TEST the unittests and have everything in one file?  That'd have saved a lot of helper code in certain cases in the past for me...)

For clarity: I don't care very much about this and I'm not going to push hard.  The thing I care most about is, style rules should pull their weight; think of each rule you add as fractionally decreasing the likelihood of all rules being remembered and followed.  Is this rule worth it?  IMO, no; it's too trivial, and I don't care if someone names their test file something different; I don't see a ton of that in the codebase and it hasn't come up in arguments.  So this isn't a fraught issue begging for a solution, and I think we just shouldn't write anything in the style guide.  Status quo is OK for me.

I bow to whatever the consensus of the group is.

PK

Michael Ershov

unread,
Jul 5, 2021, 8:11:28 AM7/5/21
to Peter Kasting, Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
I don’t have a strong opinion about naming files, but I think we already have a pretty serious problem with finding a way to run a specific test.
If we imagine that I modified some random file with a _test.cc suffix and now I want to compile and run it, it could be in unit_tests, browser_tests, components_unittests, chromeos_unittests, lacros_chrome_browsertests and probably several other binaries.
Could we introduce a way to figure this out?
Maybe enforce a comment about this in the header of test files?
Today I have to read BUILD.gn files, sometimes several layers of them and I think it’s not convenient and not simple, especially for less experienced contributors.

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.

Peter Kasting

unread,
Jul 5, 2021, 9:02:16 AM7/5/21
to Michael Ershov, Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
On Mon, Jul 5, 2021 at 5:11 AM Michael Ershov <mie...@google.com> wrote:
I don’t have a strong opinion about naming files, but I think we already have a pretty serious problem with finding a way to run a specific test.
If we imagine that I modified some random file with a _test.cc suffix and now I want to compile and run it, it could be in unit_tests, browser_tests, components_unittests, chromeos_unittests, lacros_chrome_browsertests and probably several other binaries.
Could we introduce a way to figure this out?

gn/ninja can do this, but i forget how.

PK 

Leszek Swirski

unread,
Jul 5, 2021, 9:29:43 AM7/5/21
to Peter Kasting, Michael Ershov, Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
There's gn refs, e.g.

$ gn refs out/Release services/device/wake_lock/wake_lock_unittest.cc --all          
//:gn_all
//services:services_unittests
//services/device:tests


--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.

Michael Ershov

unread,
Jul 5, 2021, 9:46:34 AM7/5/21
to Leszek Swirski, Peter Kasting, Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
That's great, thanks for the tip!

Michael Ershov

Software Engineer

mie...@google.com


Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. 

     

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.


Joe Mason

unread,
Jul 5, 2021, 11:02:07 AM7/5/21
to Michael Ershov, Leszek Swirski, Peter Kasting, Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
There's also a tools/autotest.py wrapper that takes a _*test.cc filename, finds the right test suite for it, and compiles and runs that test suite, passing through gtest params.

Jeremy Roman

unread,
Jul 5, 2021, 11:16:16 AM7/5/21
to Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, Dana Jansens, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
Adding --type=executable is great because it will give you exactly the (test) binaries and nothing else.

Dominic Farolino

unread,
Jul 5, 2021, 2:01:48 PM7/5/21
to Jeremy Roman, Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, Dana Jansens, cxx, Alexander Timin, Shivani Sharma
Do any others have strong opinions on the naming of tests? Personally I think keeping _browsertest.cc and _unittest.cc suffixes are a good idea, and I'm in favor of documenting this in the style guide.

Jeremy Roman

unread,
Jul 5, 2021, 2:35:11 PM7/5/21
to Dominic Farolino, Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, Dana Jansens, cxx, Alexander Timin, Shivani Sharma
I think my bias would be "be consistent with existing code in the area". Blink tends to use _test.cc for historical reasons; content tends to use _browsertest.cc and _unittest.cc for good local reasons.

dan...@chromium.org

unread,
Jul 5, 2021, 8:26:05 PM7/5/21
to Jeremy Roman, Dominic Farolino, Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, cxx, Alexander Timin, Shivani Sharma
On Mon, Jul 5, 2021 at 2:35 PM Jeremy Roman <jbr...@chromium.org> wrote:
I think my bias would be "be consistent with existing code in the area". Blink tends to use _test.cc for historical reasons; content tends to use _browsertest.cc and _unittest.cc for good local reasons.

I think blink has been moving toward being consistent with the rest of chromium: https://source.chromium.org/search?ss=chromium%2Fchromium%2Fsrc&q=f:unittest%20f:blink

Sylvain Defresne

unread,
Jul 6, 2021, 4:29:17 AM7/6/21
to danakj chromium, Jeremy Roman, Dominic Farolino, Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, cxx, Alexander Timin, Shivani Sharma
Chrome on iOS also uses _egtest.mm for tests of the whole app (kinda like browser tests, but they can start/stop/relaunch the app) and _inttest.mm for integration tests (between unit tests and whole app tests).
-- Sylvain

Jeremy Roman

unread,
Jul 6, 2021, 3:20:01 PM7/6/21
to danakj chromium, Dominic Farolino, Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, cxx, Alexander Timin, Shivani Sharma

K. Moon

unread,
Jul 7, 2021, 2:02:38 PM7/7/21
to Jeremy Roman, danakj chromium, Dominic Farolino, Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, cxx, Alexander Timin, Shivani Sharma
To answer the question about, "What does google3 do," it essentially boils down to the question of what Bazel does. Bazel allows test targets to be tagged with various labels; "size" is commonly used for this purpose (unit tests typically are "small", other kinds of tests are not):

If the categories are more complicated, you can use "tags" to assign arbitrary labels to a target. (I've used this in the past to mark targets that should only be executed by a certain kind of test runner.)

GN/Ninja doesn't have any of these features, AFAIK, so I'm not sure if it makes sense to import google3 practices here.

K. Moon

unread,
Jul 7, 2021, 2:03:54 PM7/7/21
to Jeremy Roman, danakj chromium, Dominic Farolino, Leszek Swirski, Peter Kasting, Michael Ershov, Avi Drissman, cxx, Alexander Timin, Shivani Sharma
Another difference is that test binaries typically are defined close to the test source files, rather than being scattered over the entire repo, and collected into just a handful of test binaries.

Peter Kasting

unread,
Jul 8, 2021, 8:46:35 AM7/8/21
to Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
How I read this thread so far:
  • Clear consensus to keep naming files the way we're currently doing (_unittest, _browsertest, etc.)
  • Positive sentiment for modifying the Chromium style guide to say to do that, since it contradicts the Google style guide.  Less clear to me that this is at "consensus" stage (or maybe I'm being overcautious?)
Are there any other opinions, especially on the second bullet?

PK

dan...@chromium.org

unread,
Jul 8, 2021, 12:18:50 PM7/8/21
to Peter Kasting, Dominic Farolino, cxx, Alexander Timin, Shivani Sharma
On Thu, Jul 8, 2021 at 8:46 AM 'Peter Kasting' via cxx <c...@chromium.org> wrote:
How I read this thread so far:
  • Clear consensus to keep naming files the way we're currently doing (_unittest, _browsertest, etc.)
  • Positive sentiment for modifying the Chromium style guide to say to do that, since it contradicts the Google style guide.  Less clear to me that this is at "consensus" stage (or maybe I'm being overcautious?)
While remembering the contents of the style guide is reasonable goal, I feel the primary purpose of the guide is to avoid disagreements in code review. When a disagreement would happen, there's somewhere to point to such that it is resolved immediately.

Since the Google guide differs it becomes worse right now as there's actually somewhere to point that increases the disagreement (guide vs code) so adding to our guide would help resolve this.
 
Are there any other opinions, especially on the second bullet?

PK

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
Reply all
Reply to author
Forward
0 new messages