Let's try to use
theoryin practice. I'm assuming that you have already a project with testing environment configured.
Your first unit tests
I'm 100% sure that you've used in your career
mapfunction. Let's try to write our implementation and later we'll add
If you're curious about performance of
reduceand other abstractions you can check our
articlein which we compared them.
Take a look at following implementation of
Usage looks a little bit different than in
Arrayprototype but mechanism is the same. Now we can add our
unit tests. We'll use conventions from this
lesson. Let's try to imagine what we want to verify - same situation like in our
Let's add the implementation for tests.
Congrats! You know the basics!
I think it's bad when developers using implementation details or refers to an API in test names.
Why I think it's bad?
You can improve that by removing references to the implementation and to the API shape. It will reduce amount of time to maintain code and will make tests like documentation.
Sometimes you need to embed implementation details or API reference in descriptions. You will know when it happens. If you have problems with creating description that's 99% the case where it's better to point to implementation details.
Remember - I'm not saying it's best practice. I'm using this approach and I pointed out arguments why. Try it and create your own opinion.
That was quick! Now we know how to test simple generic functions. Sadly, testing is much more complex. We need to dive into details in next lessons. So stay with us!
If you enjoyed it, be sure to visit us onLinkedinwhere we regularly upload content from programming.
- 1. Basics
Grouping the tests
The usage of describe and it
The best practices for naming tests
Types of tests
- 2. Mastering unit testing