# 142 - 6 Ways to improve your code tests

> Episode of [How To Code Well](https://podistic.com/podcast/how-to-code-well.md) · Published January 14, 2022 · Duration 39:09

- **Listen on Podistic:** https://podistic.com/episode/142-6-ways-to-improve-your-code-tests
- **Audio:** https://anchor.fm/s/2d0cded8/podcast/play/46120842/https%3A%2F%2Fd3ctxlq1ktw2nl.cloudfront.net%2Fstaging%2F2022-0-13%2Fbba65faa-9c5d-e996-42bf-3dcf704c00f2.mp3 (audio/mpeg)

## About this episode

Change log:

*   All the [code notes](https://github.com/howToCodeWell/course-notes) for [Docker for beginners course](https://www.youtube.com/watch?v=PbiYll21Jxg\&list=PLZdsdjcJ44WU_cY2Y1LFLnmsSjFD5BZLZ) has been written. This is available on [GitHub](https://github.com/howToCodeWell/course-notes)
*   I’ve started work on transcribing that course. This will take a long time.
*   I’ve fixed issues on [howtocodewell.net](http://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](https://youtu.be/t8w9utYu_-o)

Contact me and let me know [your thoughts or get something read out on air.](https://howtocodewell.fm/contact)

My web development courses

➡️ [Learn How to build a JavaScript Tip Calculator ](https://www.youtube.com/watch?v=l3cUp-HEmuI\&list=PLZdsdjcJ44WVa4lhVwkCtQPSG8aqgjzjK)

➡️ [Learn JavaScript arrays](https://www.youtube.com/watch?v=K3WzmRXtExg\&list=PLZdsdjcJ44WWaBGywrjhXjlJnilh6Z0NX)

➡️ [Learn PHP arrays](https://www.youtube.com/watch?v=C9gILLIyV-M\&list=PLZdsdjcJ44WUWbArkekAHznqfJ60vW8V_)

➡️ [Learn Python](https://www.youtube.com/watch?v=mYt8kFobRBc\&list=PLZdsdjcJ44WXkZs76CYt5n9pW6j3WmWeJ)

✉️ [Get my weekly newsletter](https://email.howtocodewell.net/signup)

⏰ My current live coding schedule (Times are BST)

Thursdays 20:00 = [Live Podcast YouTube](https://www.youtube.com/howtocodewell/live)

Sundays 14:30 - [Live coding on Twitch](http://twitch.tv/howtocodewell)
