Activity: Automated tests
As you read in the verification Links to an external site. chapter, there are many ways to check that your implementation is doing what's intended. And required by Homework 5, it's critical decide how you'll verify. If you don't, you won't verify thoroughly, and the result will be defects.
Your task for today will be to evaluate the benefits of writing automated tests to verify your progress as part of a continuous integration (CI) build process. The benefit of this are numerous:
- By building tests into your builds, you'll verify that everything you're testing still works every time you make a change.
- By writing tests, you'll have to be really precise about the expected behavior of your application.
- When tests fail, you'll get immediate feedback that you broke something rather than noticing much later, or after a user detects the failure.
Automated tests aren't perfect—you can't write enough tests to test everything and tests take time to write—but they are a best practice in industry. Companies that don't write automated tests are considered far, far behind the times.
Should you write tests?
The question for today's activity is whether it's worth writing tests in this project:
- If you don't write tests, you either cost yourself a lot of time in manual testing or you risk introducing defects that aren't caught until after deployment.
- If you do write tests, you pay an upfront cost to build your test infrastructure and write the tests.
One way to decide is to decide which things are most important to test and write automated tests for those. This is your task today:
- Of all of your requirements, which ones would be major failures if they didn't work?
- Of those, is it possible to write an automated test to test it?
- Try setting up an automated framework test for your application and write a basic test.
Testing with Jest
There are many libraries for writing tests of React-based web applications Links to an external site.. The simplest, and what Facebook uses to test React, is Jest. Links to an external site. Follow this helpful tutorial on setting up and using Jest to test React components. Links to an external site.Set up your build environment to do this automatically, and you'll find that writing simple tests can actually save you quite a bit of time.
PMs and Designers
Don't be passive in this meeting. Tests are what shape the quality of your work; ask the developers questions, don't let them take shortcuts because something seems too hard, and make sure the qualities you're trying to achieve in your work are reflected in your testing approach.