What is testing?
Why do we test?
What is a unit?
It is the smallest thing you can test.
It has a purpose of validating what has been specified in the design.
When you test you give the component mock data.
You don’t connect to the database for testing the data into a component rather you create an interface with fake data that are accessible by the test without any connection at all.
Integration test, which is another type of test will test connecting to data.
The goal of unit testing is to isolate and validate that what we have there is functional. Independently of anything else.
know exactly what doesn’t work and make the necessary corrections Is what we want plus the freedom to expand capabilities with constant evaluation done by these tests.
As soon as something breaks, we know what’s going on and where.
It enforces the discipline of decoupling what we are creating into the smallest possible unit.
Writing the specification testing forces the developer thinking of what are the inputs, desired output and what are the possible errors to handle while the unit is doing its job of creating the outcome it was made for.
I love that you specify the functional aspect into the tests because if the implementation changes and the specification are not met, you know where, who and exactly immediately when it breaks, so the momentum of innovating is kept going on 🙂
You won’t be able to test the overall capacity of each unit which is another type of test but you will concentrate into getting functional validation of all units independently of one another.