I was wondering, do we need Unit testing (Let's say with Jest) if we use Cypress for E2E and Component testing? When I have started writing test codes for a signin page, I see that the validation codes are same in unit test and cypress code. So, if cypress handles the unit test part, then should I add unit testing too? I am not actually finding the difference/importance of separate unit testing here.
Can you explain this?
Top comments (6)
I tend to use Cypress for highlevel, intergrating testing: Eg. Things my client will do
I use Jest for low level, function testing. Eg. thing I expect my code to do
I use valid and crazy options in my unit tests to make sure the program responds the way I want.
Generally speaking, integration tests are more important than unit tests. Especially for happy paths.
I like @tyler36's examples of using unit tests to test things that are critical and could maybe even cost you money if they go wrong. You also wouldn't want to have to use integration tests on for each of these paths either.
I have the opposite opinion. If you have a very good coverage of unit tests and individual parts are well tested, you don't actually need integration tests (or you need little of it).
If the unit tests said it was fine and the integration test failed, it was probably a failure in configuration (for the most part). That means the application would most likely not behave smoothly when running.
It's easier to notice integration failures in a running system than unit test issues.
If you are talking just about frontend, maybe the e2e is enough.
Okay, I chuckled at this because Cypress is also a life-saving device for crazy folks (we love it). en.wikipedia.org/wiki/Cypres.