> Dear blink-dev,
>
> I recently landed an almost-complete rewrite of the document that has
> best practices for writing layout tests.
>
https://chromium.googlesource.com/chromium/src/+/master/docs/testing/writing_layout_tests.md
>
> The landed version of the document is intended to be a draft that
> serves as a subject for public discussion. Please see this as an
> opportunity to reduce the number of nit comments you have to create in
> code review to help new project members get up to speed, and
> contribute your advice and fixes! The CL's code review was focused on
> removing glaring errors, so the community can focus on more subtle
> issues.
OK, let me start going through this from my POV, instead of just
responding to your email:
> [Reference tests] are only used when JavaScript tests are insufficient, such as when testing paint code
Do we mean to encourage testing layout things with CSSOM? (e.g.,
checking a box in positioned in the right place and right size?) This
is /mostly/ the status quo, but isn't the habit in csswg-test and on
the whole I would expect this to continue when that is merged into
web-platform-tests.
> Dump Render Tree (DRT) Tests output […]
I think it'd be kinda useful to mention *when* you'd want to use such
a test, given they test implementation detail. (i.e., you want to use
them essentially iff you're testing you get a specific render tree,
otherwise your goal is to test you get the right final result)
> The principles below are adapted from Test the Web Forward's Test Format Guidelines and WebKit's Wiki page on Writing good test cases.
FWIW, making the WPT documentation, which is currently on TTWF, saner
and easier to navigate, and likely doing copy editing of it, is on my
to-do list for, uh, this month; if there's anything you think that
should be there, file bugs on the w-p-t repo or email me, plz!
Also, the first bullet points seems not to be getting rendered
correctly, given there appear to be bullet points not rendered within!
> The desire to use modern features must be balanced with the desire for cross-platform tests. Avoid using features that haven't been shipped by other developed major rendering engines (WebKit, Gecko, Edge). When unsure, check
caniuse.com.
As mentioned in my prior email, this should probably include avoiding
features we haven't shipped in a stable release to match the WPT
policy (obviously, this doesn't apply to the feature under test!).
> Furthermore, layout tests should include relevant metadata. The specification URL (in <link rel="help">) is almost always relevant, and is incredibly helpful to a developer who needs to understand the test quickly.
I think it's worthwhile to note we've been trying to *reduce* the
amount of metadata required in CSS tests (for one, almost all of it is
now per-resolution optional, though the implementation of making some
of it optional is yet to happen!).
The spec URL is IMO relatively rarely actually useful: in most cases
in web-platform-tests, the directory structure and filename can tell
you just as much as the spec URL can.
Requirement flags are almost entirely unused by anyone (their
practical uses are mostly superseded by -manual or -visual suffixes on
the filename).
Assertions are in the opinion of many better placed as comments close
to what is actually being tested and little value is got out of
putting them in a meta element, even if the CSS WG's official view is
that it's better to have it in a standard machine-readable format (I
think we should ignore the WG and do what *we* think is best, because
the policy is only a recommendation not a requirement, and potentially
in future lobby to change it).
> New reference tests should follow the WPT reftests guidelines.
I think another important point to include is: "Note that references
can be shared between tests; this is strongly encouraged since it
permits optimizations when running tests."
Some fairly simple references can be used by hundreds (or even
thousands!) of tests; one that occurs frequently in the CSS test
suites simply reads: "Test passes if there is a filled green square
and no red." with a 100px green square below—that's something that
most box-sizing tests can use.
Through the sharing of references, it's possible to cut out thousands
of page loads per test run by caching reference renderings.
HTH,
/gsnedders