Table tests are only a good fit for some portion of that gradient. Some of them can make use of tables, but the entire test should look like a gradient of increasing complexity and assurance in my opinion. Note that these tests are essentially sequential because each test relies on assumptions that are thought to be verified by earlier tests. And then I optionally write more expensive tests to fill any remaining gaps-exhaustive testing, randomized testing, property testing and so on. For example if some function `f(x, y)` requires both `x` and `y` to be a square number, I can reasonably expect that such check happens before anything else so we can only feed square numbers when we are confident enough that checks are correct. Then I map out edge and negative cases, but with a knowledge of some internal working in order to prune them. When I write a specific set of tests I first start with representative positive cases, and I think you would call them as a storybook test (because it serves both as a test and an example). Table tests (ideally) represent a pruned tree of possibilities that make intuitive sense to humans, but that pruning itself doesn't always neatly fit into tables. If you need to test all permutations and combinations, do the exhaustive property testing instead. It leads to good tests and helps you reason about your inputs. > he process of writing the inner part of the table test seems to nudge you to think about all the permutations and combinations of what you're testing can be. But when I sit down and write a new test, I'm usually imagining it as one of these two archetypes of tests. Mind you reality is messy so tests often blur and blend and so on. What the test represents is that some flow is important, gives an example of it, and helps show that this general use-case is what we want to keep working, not necessarily these specific state transitions. But more often than not I argue that the story itself is more valuable than exactly what permutations of the inputs and state get tested at each call. You may argue: aha! This is a state machine and you ought to simply independently test each state transition! Fair enough, I say, and yes in some cases I might actually do so if the API that's exposed lends itself to having its internal state set so explicitly. The other kind of test is what I call a "storybook test." Table tests are less useful here, this is usually for testing CRUD in a coherent manner but can apply to any kind of object that has a lifecycle that you need to transition between various states. One is "I'm testing a bunch of different variations of the same thing." Table tests are great for this, they make the code pretty readable and, perhaps more importantly, the process of writing the inner part of the table test seems to nudge you to think about all the permutations and combinations of what you're testing can be.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |