7 ms·
What I wish people had told me about testing: * You write tests in accordance with a pattern: 1. Arrange 2. Act 3. Assert 4. Annihilate If you annihilate
by AlwaysBCoding 13y ago
What I wish people had told me about testing:
* You write tests in accordance with a pattern:
1. Arrange
2. Act
3. Assert
4. Annihilate
If you annihilate your test data with configuration options, and you abstract your "arranging" into factories and custom methods, then every test you write should be exactly three lines. When I learned this it gave me a consistent mental framework to think about how to write good tests.
* Test the interface not the implementation:
This was an eye opening realization about what to test. If you haven't seen it yet, watch Sandi Metz' incredible RailsConf talk - http://www.youtube.com/watch?v=URSWYvyc42M http://www.youtube.com/watch?v=URSWYvyc42M - it's so good
* Stubs:
Stubs are exactly like the viruses' that we learned about in biology class. You load them up with a value then they literally latch onto a method and inject that value into it. When you're just starting out with testing, effective use of stubs can get you really far, and only when you start hitting the limits of practicality is when you need to think about bringing in something more complicated.
* Testing isn't easy per se, but it is definitely enjoyable if you focus on making it that way
* Cucumber is pretty stupid, don't waste your time with it
- charlietran 13y agoThat video was excellent, thank you! Sandi Metz always comes up with great analogies that clear up the conceptual fog in my mind. Her book Practical Object Oriented Design in Ruby is a great read too.