-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
proposal: table test guidance is too prescriptive #173
Comments
Agreed! This came up in #167 as well. The high-level guidance that some of us discussed in the past includes: Keep table tests simple. Don't add complex, branching pathways. We're completely in agreement on this. CC @mway @prashantv since we were discussing this recently. A separate guidance we've discussed similar to DRY vs DAMP tests is: |
+1 to @abhinav. A specific |
Table tests are great for reducing repetition, but as the SUT becomes more complex, they become harder to read, maintain, and debug.
Making tests harder to read and maintain at scale negatively impacts velocity, productivity, and overall sentiment on testing.
One common pattern I notice is with logical branches based on variables like
shouldError
,shouldCallExecutor
,shouldDoXYZ
. This creates an extremely difficult-to-read set of tests. As an exmple, consider the following test:These tests are confusing. It's hard to tell what's going to be checked in which conditions, and unclear when certain fields of the
tests
struct are even used. The reader has to reference logic within thetests
structs, as well as the complex behavioral logic within the test loop to understand what's happening.Consider again that I need to add another subsystem to the service that has a mock which is called only some of the time. This adds another layer of complexity to the table test, and potentially obstructs all previously written parts of the table.
Having the guidance push to use Table Tests for "repeated patterns" actually can negatively impact code quality. Rather than recommending Table Tests for such patterns, we should recommend using Table tests for situations when ONLY the inputs and outputs of the system differ. It would also be good to recommend to AVOID Table Tests with logic existing inside the test loop.
Aside:
Somewhat unrelated to style, but it's also harder to maintain tests at scale with the dynamic assignment of subtest names. Splitting up table tests more granularly into separate
TestXXX
functions makes it easier to keep track of the speed and reliability of tests.The text was updated successfully, but these errors were encountered: