Welcome back to another episode of the Evil Geniuses Podcast. We are coming at you with something new this week! This episode will be the first time that we are not talking about a code problem that we’ve solved because we are going to take a stand, and our stand is about testing. We are diving into the ins and outs of how you describe your test. Here at Evil Geniuses, we believe that the description of a test should describe business value not implementation.
So stay tuned as we unpack the differences between business value and implementation descriptions, the opportunities that can come from rewriting code, and why naming your tests can take quite some time to fully master. For all this and more, keep listening!
Key Points From This Episode:
- Specific examples describe business value versus implementation.
- How the description sets you up to know what to look for when reading the test.
- Why a misdescription can make it hard to see if the test was successful.
- Understanding exactly who the test naming is for.
- Rewriting code allows you to know enough to better write business value descriptions.
- Why naming your tests takes a long time to master.
- And much more!
Talking Points
Tests should describe the business value and not the implementation
- Different types
- Test that describes implementation:
-
- describing that a method or attribute returns a certain value
- “it should equal 20”
- “it should call YouTube API”
- “it should call the render_text method”
- Test that describes business value
- describing the reason to return a certain value
- “it should have the amount given by the user”
- “it should return video stats”
- “it should render text”
- Who are the tests for?
- Other developers reading the code
- Future you if you’re refactoring
- Following this practice results in better tests
- Bad: “it should raise a PriceError”
- Good: “it should return an error when value exceeds max price”
- Not only about raising the error; it’s about notifying the developer and user that something exceeded the max price
- Supports Refactoring
- clarifies the objective
- this makes it easy to change implementation because you aren’t confused about why a certain piece of code was written
- Ex: feel confident to refactor as long an error is raised when the max price is exceeded
- Supports Feature Changes
- Feel more confident changing or removing test related to max price with description instead of just “exceeds 100”
Links Mentioned in Today’s Episode:
Evil Geniuses on Twitter
The Stand
Stride
Information
- Show
- FrequencyUpdated Semimonthly
- PublishedNovember 14, 2018 at 8:00 AM UTC
- Length21 min
- Episode14
- RatingClean