How To Code Well
142 - 6 Ways to improve your code tests

142 - 6 Ways to improve your code tests

How To Code Well

39:09

About this episode

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

Watch the show on YouTube

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 JavaScript arrays

➡️ Learn PHP arrays

➡️ Learn Python

✉️ Get my weekly newsletter

⏰ My current live coding schedule (Times are BST)

Thursdays 20:00 = Live Podcast YouTube

Sundays 14:30 - Live coding on Twitch

More from How To Code Well

Let's talk about how to test code that you don't controlShow notes: https://howtocodewell.net/podcast/episode/219Support the show and get early access to tutorials courses and moreYouTube membership h…

39m

In today's I practice a new PHP talk that I am hoping to give to PHP user groups this year. The talk is called how to make your PHPUnit tests smarter. Show notes: https://howtocodewell.net/podcast/epi…

50m

In today's show we discuss more Laravel tutorials and look at what is coming in Laravel 12 Show notes: https://howtocodewell.net/podcast/episode/217Support the show and get early access to tutorials c…

23m

In today's show we discuss more Laravel tutorials and dip our toes deeper into the world of OOP. Support the show and get early access to tutorials courses and more YouTube membership https://www.yout…

41m

Today we are going to talk about Laravel collections, conferences and object orientation. Show notes: https://howtocodewell.net/podcast/episode/215 Support the show and get early access to tutorials c…

41m