1

We have used React JS for front end and we need to write end to end tests. After researching online, we came across 2 options :

1. Selenium WebDriver
2. React Test Utils (https://reactjs.org/docs/test-utils.html)

What I understood was that with React Test Utils you can simulate clicks and check the status of the HTML elements by using methods like findRenderedDOMComponentWithXXX and that you can run these tests from command line so they will be faster.

Selenium does the same thing but from within the browser, it will allow you to write test in Behavior Driven Development Style(making it more readable)

My confusion :

  1. Can we use React Test Utils to test a complete web page (complex component) or it is better to only test simple custom made components. For example: If we have a component like Tasks which allows you to add tasks, remove tasks, change priority which uses components like Input, DropDown and Toggle.

    So is it a good idea to use React Test Utils for the entire Tasks component or we should use it for smaller inidividual components like Input, DropDown, Toggle

  2. To test the complete Tasks component write end to end tests using Selenium.

Some other points :

  1. simulate method in React Test Utils requires to pass event data which can increase small amount of work.

It will be great if some one can help me understand the difference between two.

j10
  • 2,009
  • 3
  • 27
  • 44

1 Answers1

2

You can use Jest and Selenium together. Don’t limit yourself to just one. You probably will go even beyond those two when you do Test Driven Development, or even Behavior Driven Development, based on what specifically you need to test. Jest by itself can’t really simulate UAT in my opinion. You need to open the browser to fully simulate the user experience, but those browser tests could be a very small percentage of tests relative to all of your tests. The reason why so many people have moved away from selenium is the bulkyness of configuration and maintenance of it. Also speed and reliability.

There are newer tools coming to life for browser based testing in recent years:

Puppeteer

https://github.com/GoogleChrome/puppeteer

Nightwatch.js

http://nightwatchjs.org

Also, your specific programming language offers additional features and enhancements to testing. Many Java developers use Maven and TestNG with their testing to build and debug their tests. Ruby developers might use RSpec. Whatever test runner you use, it might incorporate several dependencies on the backend for all kinds of testing tools for linting, html proofing, functionality, DevSecOps, database migrations, or even spellcheck. The key is to group all the tests you think you will need together in a single test runner (preferably, or as few as possible). Then run them all, back to back in a CI/CD pipeline; like Jenkins prior to deployment of changes. If any one fails, then your build fails in real time.

If you want to run several API tests in the pipeline, Newman is looking pretty decent to incorporate Postman tests you may already have laying around into a CI/CD pipeline. Of course alternatively, you could also build http clients, but not everyone has a coding skill set, so the tools you pick first should compliment the skillsets you have available to you as well.

Smart Bear also has several tools now that will run in a CI/CD pipeline for SOAP and UI testing, but those are much more expensive than the open source alternatives.