Go offline with the Player FM app!
142 - 6 Ways to improve your code tests
Manage episode 317514406 series 2674787
Change log:
- All the code notes for Docker for beginners course has been written. This is available on GitHub
- I’ve started work on transcribing that course. This will take a long time.
- I’ve fixed issues on howtocodewell.net regarding signup, forgotten password and other minor fixes
- I’ve added the functionality to lock and unlock courses. This will turn them into private or public courses that require enrolment
6 ways to improve your testing
1) Automate as much as you can
- Use CI pipelines
- Run these locally even if your’e not committing any changes
- Include other code auditing tools such as phpstan or phpmd
2) Statics are evil
- There is no way to test a static method that calls another static method
3) Having many mocks is an indication of bad code design
4) Use tests to help refactor you code
- If a unit of work cannot be easily tested then it usually means the code is not designed well
- Break up your tests into smaller chunks
- Tests can highlight micro and minor refactors
- Refactor your code and then re test
- Try and do this in a TDD fashion
5) Avoid flaky tests
- Clean up state
- Check for bottle necks which could cause timeouts
- Mock external services or dependancies
- Look into potential memory leaks
6) Re think what testing means to you
- Testing is a contractual agreement between the programmer and the code
- Testing is documentation - Gherkin, Acceptance Criteria, Business requirements
- Testing is boundary setting which helps with focus
- Testing is future proofing
Contact me and let me know your thoughts or get something read out on air.
My web development courses
➡️ Learn How to build a JavaScript Tip Calculator
➡️ Learn Python
⏰ My current live coding schedule (Times are BST)
Thursdays 20:00 = Live Podcast YouTube
Sundays 14:30 - Live coding on Twitch
216 episodes
Manage episode 317514406 series 2674787
Change log:
- All the code notes for Docker for beginners course has been written. This is available on GitHub
- I’ve started work on transcribing that course. This will take a long time.
- I’ve fixed issues on howtocodewell.net regarding signup, forgotten password and other minor fixes
- I’ve added the functionality to lock and unlock courses. This will turn them into private or public courses that require enrolment
6 ways to improve your testing
1) Automate as much as you can
- Use CI pipelines
- Run these locally even if your’e not committing any changes
- Include other code auditing tools such as phpstan or phpmd
2) Statics are evil
- There is no way to test a static method that calls another static method
3) Having many mocks is an indication of bad code design
4) Use tests to help refactor you code
- If a unit of work cannot be easily tested then it usually means the code is not designed well
- Break up your tests into smaller chunks
- Tests can highlight micro and minor refactors
- Refactor your code and then re test
- Try and do this in a TDD fashion
5) Avoid flaky tests
- Clean up state
- Check for bottle necks which could cause timeouts
- Mock external services or dependancies
- Look into potential memory leaks
6) Re think what testing means to you
- Testing is a contractual agreement between the programmer and the code
- Testing is documentation - Gherkin, Acceptance Criteria, Business requirements
- Testing is boundary setting which helps with focus
- Testing is future proofing
Contact me and let me know your thoughts or get something read out on air.
My web development courses
➡️ Learn How to build a JavaScript Tip Calculator
➡️ Learn Python
⏰ My current live coding schedule (Times are BST)
Thursdays 20:00 = Live Podcast YouTube
Sundays 14:30 - Live coding on Twitch
216 episodes
All episodes
×Welcome to Player FM!
Player FM is scanning the web for high-quality podcasts for you to enjoy right now. It's the best podcast app and works on Android, iPhone, and the web. Signup to sync subscriptions across devices.