Sign in
Log inSign up
Mario Cervera

127 likes

·

1.8K reads

18 comments

Darren Finch
Darren Finch
Jan 7, 2021

This is a terrific article! I like the writing style and the content.

Honestly I need to establish a better unit testing habit. I don't unit test my personal projects often because TDD feels foreign.

Which also leads me to ask, did TDD feel foreign to you at first?

If so, how did you adapt?

1
·
·1 reply
Mario Cervera
Mario Cervera
Author
·Jan 7, 2021

Thanks for your kind words Darren! 🙏

Be careful with TDD. Let me explain. It is a hard practice to master. You need to be good at testing, design, and refactoring, among other things, so it's definitely not the first thing you want to learn when you are inexperienced.

I'd say that you should develop the habit of writing automated tests first, and, eventually, you can try the TDD process, to see if it's a good fit for you.

That's more or less what I did. I didn't try TDD until I was confident with my design and testing skills.

I hope this helps!

·
Reza Lavarian
Reza Lavarian
Mar 1, 2021

Automated tests play the role of code samples.

I'd like to emphasize this sentence, code samples are super helpful.

It even affects the whole design of a feature. Especially, when developing the API, first, and then the implementation, like how we do in TDD.

Good writing style, by the way. Thanks!

1
·
·1 reply
Mario Cervera
Mario Cervera
Author
·Mar 1, 2021

Thanks Reza! 🙏

Yes, that's an important benefit. When we write tests, we are effectively using our APIs. If the design is bad, our tests will suffer (e.g. they will be less readable). This is one of the ways testing has a strong positive impact on design.

1
·
Jov Mit
Jov Mit
Oct 26, 2020

That's an awesome article, I have to admit that I loved it a lot.

Really nice writing style, easy to read and understand. No complex sentences and very good arguments. It would be of a great benefits for the community around you if you keep posting such good content with this writing style.

Little remark about the following:

through the use of test doubles, also known as mocks

I talk about that in my last weekly video on youtube 👇, and basically there is some history of why the term Mocks is used in generic context to refer to all Test-Doubles, but the actual mock is a kind of test-double just like the stub, dummy, spy and fake.

Would be interesting to see your opinions on that especially after watching the video: youtu.be/YQ9qlcq6Yyg

·
·2 replies
Mario Cervera
Mario Cervera
Author
·Oct 26, 2020

Thanks Jovche for the feedback!

I am aware of the different types of test doubles. I typically use the terminology that is presented in the "xUnit Test Patterns" book. But, in this article, I used the term "mock" because it's well-known by many people, despite the fact that, as you rightly suggest, it is just yet another type of test double.

You can expect my feedback on your video soon 😉

1
·
Jov Mit
Jov Mit
Oct 26, 2020

It's lovely to see we are on the same page :) Indeed the term is widely used and know in the community 💯👌

1
·
Apoorv Tyagi
Apoorv Tyagi
Oct 26, 2020

Nice Article Mario Cervera. Enjoyed reading every point you have mentioned

Very Clear & concise points👍

·
·1 reply
Mario Cervera
Mario Cervera
Author
·Oct 26, 2020

Thanks Apoorv! Glad to hear that you liked it! This kind of feedback encourages me to write more posts in the future 😊

·
Maxi Contieri
Maxi Contieri
Oct 26, 2020

Amazing as usual, Mario !

·
·1 reply
Mario Cervera
Mario Cervera
Author
·Oct 26, 2020

Thanks Maxi! I really appreciate it! Getting such positive feedback, no doubt that I will write more articles soon 😉

·
Matt Moll
Matt Moll
Oct 27, 2020

Amazing as always Mario! Looking forward to a nice post about clean code and more examples about testing!

Thanks for sharing!

·
·1 reply
Mario Cervera
Mario Cervera
Author
·Oct 27, 2020

Thanks Matt! Those posts that you mention will come, eventually 😉

1
·
Fortune
Fortune
Oct 29, 2020

I have a few questions?

  1. Is there such a thing as "over testing"?

  2. What is the industry benchmark for percentage coverage?

·
·2 replies
Mario Cervera
Mario Cervera
Author
·Oct 29, 2020
  1. Yes, there's such a thing. Your time is not infinite, so you cannot possibly test everything or automate everything. You want to automate tests that prove different things, so that they are more useful. For example, to test a "multiply" function, it is probably better to use as test inputs (3,0), (7, 16), (-2,8), and (1242362234, 35674563), which prove different things, than using (1, 1), (2,2), (3,3), and (4,4), which leave some corner cases untested.

  2. No, there is no benchmark. The ideal is 100%, but it is unattainable, and, at the same time, anything less than 100% can be considered bad (because you want a 100% of your app to work, right?). My opinion is that you have to use code coverage as a "motivation metric". That is, always try to improve it, knowing that you won't reach 100%, but the higher the better.

2
·
Fortune
Fortune
Oct 30, 2020

Mario Cervera Thanks for your reply

1
·
Deactivated User
Deactivated User
Deactivated User
Oct 29, 2020

Thanks Mario, great article!

Tests help you detect errors early, when they are cheapest to fix.

Agreed 100%. The sooner you fix it, the more time you will save in the future.

·
·1 reply
Mario Cervera
Mario Cervera
Author
·Oct 29, 2020

Thanks Nick! I am happy that you like it 😊.

Yes, short-sighted people usually argue that testing slows the team down, but they fail to consider the savings that come in the future!

2
·