If you don’t write unit tests… it’s a skill issue

Today i come across this tweet:

// Detect dark theme
var iframe = document.getElementById(‘tweet-1837055371589955632-479’);
if (document.body.className.includes(‘dark-theme’)) {
iframe.src = “https://platform.twitter.com/embed/Tweet.html?…


This content originally appeared on DEV Community and was authored by Manuel Artero Anguita 🟨

Today i come across this tweet:

// Detect dark theme var iframe = document.getElementById('tweet-1837055371589955632-479'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1837055371589955632&theme=dark" }

which reads

Does anyone have any written articles or anything telling what strategies they have used to introduce their colleagues to the wonderful art of testing? In cases where they say "I don't agree with tests."

this part:

"I don't agree with tests."

oh my dear, this isn't about an active stance. Considering the generation tools we have today, I'm afraid...

It's a skill issue

I've been there.

  • You know the theory: tests are good for the codebase.
  • They act as documentation for devs.
  • They offer coverage.
  • They give peace of mind.

But here's the real problem. It's not about a "stance." It's just that you don't know how to write the test.

And you've tried with the official docs, which look something like this:

function foo() { return 42; }

expect(foo()).toBe(42)

You already know how to test a simple "input-output" function.

But in the real world, things are more complicated...

  • You want to test a React component, but it depends on 4 contexts, page location, and a router?
  • You want to test a Node.js object, but it depends on 8 external libraries, has a messy internal state, and needs some obscure pre-fetching from Dracula’s castle?
  • You want to test a Python class, but it’s tied to RabbitMQ, and getting the system ready is a nightmare?

The first step is admitting: it's a skill issue.

And that's ok

Testing is a skill. And it's different from regular coding.

Start small, break down the dependencies, and isolate the parts you can control.

Control is the key:

The moment you can test your "component" is the moment you fully control your code.

*"component" as an abstract term, your class, your module, your system...

you know when i did finally understand-understand (like really understand) React contexts ? when i was able to test them!

Mocking libraries exist for a reason. Master the tools available, whether it’s Jest, Playwright, Pytest...

Remember, it's a skill. And like any skill, it can be learned.

It’s a process.


This content originally appeared on DEV Community and was authored by Manuel Artero Anguita 🟨


Print Share Comment Cite Upload Translate Updates
APA

Manuel Artero Anguita 🟨 | Sciencx (2024-09-20T10:49:54+00:00) If you don’t write unit tests… it’s a skill issue. Retrieved from https://www.scien.cx/2024/09/20/if-you-dont-write-unit-tests-its-a-skill-issue/

MLA
" » If you don’t write unit tests… it’s a skill issue." Manuel Artero Anguita 🟨 | Sciencx - Friday September 20, 2024, https://www.scien.cx/2024/09/20/if-you-dont-write-unit-tests-its-a-skill-issue/
HARVARD
Manuel Artero Anguita 🟨 | Sciencx Friday September 20, 2024 » If you don’t write unit tests… it’s a skill issue., viewed ,<https://www.scien.cx/2024/09/20/if-you-dont-write-unit-tests-its-a-skill-issue/>
VANCOUVER
Manuel Artero Anguita 🟨 | Sciencx - » If you don’t write unit tests… it’s a skill issue. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/20/if-you-dont-write-unit-tests-its-a-skill-issue/
CHICAGO
" » If you don’t write unit tests… it’s a skill issue." Manuel Artero Anguita 🟨 | Sciencx - Accessed . https://www.scien.cx/2024/09/20/if-you-dont-write-unit-tests-its-a-skill-issue/
IEEE
" » If you don’t write unit tests… it’s a skill issue." Manuel Artero Anguita 🟨 | Sciencx [Online]. Available: https://www.scien.cx/2024/09/20/if-you-dont-write-unit-tests-its-a-skill-issue/. [Accessed: ]
rf:citation
» If you don’t write unit tests… it’s a skill issue | Manuel Artero Anguita 🟨 | Sciencx | https://www.scien.cx/2024/09/20/if-you-dont-write-unit-tests-its-a-skill-issue/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.