4. Premises of (Automated) Testing
- Gain confidence that the software works correctly 😤
- Confidence is a product of authenticity 🪞
- Authentic test processes provide more confidence
- Contrived test processes provide less confidence
- Some components may be hard to test 🪞
- Because they are not easily accessible (e.g. cloud services)
- Because they are non-deterministic (e.g. dependent on outside effects)
- Because they are slow (e.g. relying on heavy I/O or computations)
- They can be replaced with test doubles
- Their behavior can be tested in isolation
- This reduces authenticity and thus confidence
tyrrrz.me
Prioritize this
Avoid this
6. Reasons to Use Real Dependencies
- Overuse of test doubles erodes confidence 🧑
- Less of the actual application surface is tested
- Potentially impossible states may be tested
- Especially when mucking with internal state
- Crucial infrastructural concerns are not tested
- Database interactions
- Request routing & handling
- Mocks make tests more complicated 🧑
- Tests should be trivial to understand
- Tests should not rely on implementation details
- Tests that contain logic need other tests to test themselves
- But we can’t just use real dependencies… 😔
- …or can we?
tyrrrz.me
12. Performance Considerations
- Docker Pull is the slowest part 🐌
- Mostly just affects CI environments
- Many platforms pre-cache popular images
- Reducing image size is important
- Cold start overhead is constant ❄️
- Test suite becomes more efficient as it grows
- More tests means faster relative execution time
- Different isolation strategies can yield better results
tyrrrz.me
13. Test Isolation Strategies
- No isolation 🚫
- All tests share the same environment
- Environment gets reset after each test
- Tests cannot be parallelized
- Domain isolation 🛍🧑
- All tests share the same environment
- Operations are scoped within a logical scope (e.g. tenant)
- Each test gets its own scope
- Storage isolation 📝
- All tests share the same environment
- Each test gets its own database instance
- Environment isolation 📦
- Each test gets its own environment
tyrrrz.me
14. Summary
- Testing against real dependencies…
- Is easy (as long as there’s a Docker image) ✅
- Is quite fast ✅
- Simplifies testing code ✅
- Provides more confidence ✅
- TestContainers…
- Supports many different development platforms ✅
- Lets you easily share test infra between projects ✅
- Testable software…
- Is not just about dependency inversion and interfaces ❌
- Is sometimes just about using the right technologies ✅
tyrrrz.me