Start with one test

start-with-one-test

Throwaway projects aside, would you say testing is important?

Tests are important butโ€ฆ

It takes too much timeโ€ฆ

We donโ€™t have time for thatโ€ฆ

I donโ€™t know how toโ€ฆ

I do it manuallyโ€ฆ

My code is perfect!

Howeverโ€ฆ

Have you ever had the need to fix something for someone just for it to break it to someone else?

How about fearing touching the files someone else created?

How about it โ€œjust stopped workingโ€ and when you finally found out why it was because some dependency changed something (or someone changed a file you are dependent on)?

Are you debugging or manually testing, again the code youโ€™ve been debugging and manually testing since last week?

And what happenedย wasโ€ฆ

To lose a lot of time chasing a bug that appears out of nowhere or to dredge through the work of someone else.

Test is likeย coding

Remember learning to code?

Your first tests will be awful, but they will still help you.

Hereโ€™s an example:

GitHub logo

Noriller
/
one-test

Start with one test!

One test!

If you don’t have any tests, anything is already better than nothing.

So start with one test.

Check out and choose which one you prefer:

And then start testing one component, one process, one “happy path”.

How to use this

I used pnpm here, so you need to have pnpm installed globally.

pnpm install

# unit tests
pnpm test

# e2e tests
pnpm test:cy

Outro

Happy testing!

I purposely made this as naive as possible. The biggest problem is that itโ€™s โ€œflakyโ€, but there are others.

Being flaky means that changes will easily break the test, meaning you will have to fix the tests every time you change the code if you test them like this.

Butโ€ฆ it will work, it will help and even save more time than if you were doing it all manually or just hoping it doesnโ€™t break.

And as you learn how to test and best practices youโ€™ll start refactoring your tests (yes, tests are also code that should be refactored) and making more resilient tests, with fewer bugs (yes, tests can also have bugs), also tests that test more than just if itโ€™s working (example: you can test accessibility by using selectors that work with semantic tags and roles).

The more youย testโ€ฆ

In my experience, the more I test and the better the coverage, the less I have to rely on manually using it on every change and even less I have to debug.

Not only that, everyone on the team benefits from those tests. They are already there and telling you what should be working and how. And when something breaks, it tells everyone exactly where.

If you get a tested piece of software, you donโ€™t need to know and keep in your mind all the complex rules the code needs to work, so when you need to refactor or change it, you will always know if it’s still working or not and be able to catch if the breaks on the test are intended or not.

Soโ€ฆ what other benefits do you find with testing or what still holds you back from testing?

Photo by National Cancer Institute on Unsplash

Total
8
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
processing-user-input-in-bubble-tea-with-a-menu-component

Processing user input in Bubble Tea with a menu component

Next Post
movin’-on-up:-an-analysis-of-the-privilege-escalation-vulnerability-cve-2022-26923

Movin’ On Up: An Analysis of The Privilege Escalation Vulnerability CVE-2022-26923

Related Posts