When testing, lean towards DAMP 💧
By Google for Developers
Key Concepts:
- DRY (Don't Repeat Yourself) principle in testing
- DAMP (Descriptive And Meaningful Phrases) principle in testing
- Test readability
- Helper methods in testing
- Balancing DRY and DAMP principles
Readability vs. Uniqueness in Testing
The video emphasizes that while the DRY (Don't Repeat Yourself) principle is generally good practice, tests should prioritize readability, even if it means some repetition. The core argument is that tests are verified by humans, not by other tests, so clarity is paramount.
DRY Example and its Drawbacks
The video presents an example of a test that adheres to the DRY principle. It avoids duplication, uses helper methods, and employs loops for efficiency. However, the speaker argues that this test, while clean, requires mental computation to understand. Specifically, the viewer needs to trace self.users from the setup through the helper method to the test itself, which involves "jumping around" in the code.
DAMP Example and its Advantages
The video then presents a "DAMP" (Descriptive And Meaningful Phrases) version of the same test. This version contains some duplication, but all the relevant information is directly within the test itself. The speaker asserts that this makes the test much more readable because "no mental computation [is] needed." The key point is that humans need to be able to easily verify tests by reading them, which distinguishes them from production code.
Balancing DRY and DAMP
The video clarifies that DRY is still useful in testing. Helper functions for creating objects are considered beneficial. However, when a choice must be made between DRY and DAMP, the video advocates leaning towards DAMP to enhance readability.
Actionable Insight
The actionable insight is that readable tests are more effective at catching bugs. The video concludes by prompting viewers to share their own strategies for balancing repetition and readability in their tests.
Notable Quote:
"Because tests don't have tests, humans need to be able to verify by reading them." This statement encapsulates the central argument for prioritizing readability in testing.
Chat with this Video
AI-PoweredHi! I can answer questions about this video "When testing, lean towards DAMP 💧". What would you like to know?