[wp-trac] [WordPress Trac] #53119: Tests: introduce naming conventions for data providers and use named test cases
WordPress Trac
noreply at wordpress.org
Fri Apr 30 21:03:11 UTC 2021
#53119: Tests: introduce naming conventions for data providers and use named test
cases
------------------------------+------------------------------
Reporter: jrf | Owner: (none)
Type: task (blessed) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Build/Test Tools | Version:
Severity: normal | Resolution:
Keywords: | Focuses: docs
------------------------------+------------------------------
Comment (by jrf):
@pbiron I see your point. Having the data providers always at the bottom
of the class makes it very ''predictable''.
However, good test functions are short, a few lines at most, so even when
the data provider would be for three tests, in most cases, having the data
provider follow the tests it applies to, would still mean that both the
tests as well as the (start of) the data provider function would fit onto
one screen, making it easy to understand what the data sets mean as the
parameter descriptions for the test functions are on that same screen.
This would rarely be the case when the data providers are at the bottom of
the file, which implies that you'd ''always'' have to jump around the file
to figure out what the various parts of each data set means, raising the
cognitive complexity.
Now, you might say: "hang on, but there are a lot of test functions which
aren't short"....
In that case, you would be correct, but I did say I was talking about
''good'' test functions.
As soon as a test function needs more than a few lines, it generally is a
sign that the function under test is too complex and should be split up or
even be a class instead of a function. So, complex tests in more a symptom
of an underlying architectural problem and should not be guiding us in
this.
> Both the proposal and your way provide consistency when applied
consistently. Both can aid in making the test suite more consistent.
Consistency can help contributors to know how to structure tests. That's a
win.
And on this I have to agree with @hellofromTonya: anything is better than
the messy inconsistency we currently have... 🥴
Another thing which comes to my mind while reading though this discussion,
is: what about test helper functions ? Should we set a convention for the
placement of those ?
In my ''opinion'', test ''helper'' functions should always be at the
bottom of a test class (or in an abstract test case). What do you think ?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53119#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list