DEV Community

Anower Jahan Shofol
Anower Jahan Shofol

Posted on

Do I need Unit testing if I use Cypress?

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)

Collapse
 
tyler36 profile image
tyler36

I tend to use Cypress for highlevel, intergrating testing: Eg. Things my client will do

  • visit site and login
  • create a new blog page
  • purchase a new item

I use Jest for low level, function testing. Eg. thing I expect my code to do

  • Validate usernames are a-z only by checking ['apple', 'apple123', 'apple🍎' ]
  • Discounts are properly applied by checking different values ['10', '20', null, false, '10%', '-30']

I use valid and crazy options in my unit tests to make sure the program responds the way I want.

Collapse
 
jaredkotoff profile image
Jared Kotoff

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.

Collapse
 
amexboy profile image
Amanu

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.

Collapse
 
justaguyfrombr profile image
Misael Braga de Bitencourt

If you are talking just about frontend, maybe the e2e is enough.

Collapse
 
amexboy profile image
Amanu

Okay, I chuckled at this because Cypress is also a life-saving device for crazy folks (we love it). en.wikipedia.org/wiki/Cypres.