Testing workshop
With professor Ronen Amiel
Agenda
- Talk about tests and why we write them.
- Live code a simple tic-tac-toe game.
- You clone the repo and continue to work on the game.
- From 16:00-19:00 we start the final exam and list homework for tomorrow morning (chapters 2-5).
Why write tests?
Why write tests?
-
You should write tests if you value your time:
-
Changing the code base doesn't require manually verifying that everything still works.
-
Deploying new versions requires little or no manual testing.
-
-
You'll have confidence your code still works after someone changed it.
-
It's easier for new team members to get into the code base.
You should write tests if you value your time
-
Changing the code base doesn't require manually verifying that everything still works.
-
Deploying new versions requires little or no manual testing.
- Reviewing others' code isn't about finding bugs but about design and quality.
You'll have more confidence over your code
- You'll have confidence your code still works after someone changed it. This also includes refactoring.
- Rollbacks happen a lot less often. When they do, you add a test that covers the cause for the rollback so it doesn't happen again.
- New team members can rest assured that their changes did not break any existing behavior.
Why TDD?
- Know that every line and edge case are covered by a test (well, mostly).
- Tests are good only when you trust them: TDD helps you write tests you trust.
- Instead of manually re-creating a use-case (normally, on the browser) use a as a way of re-creating the use-case.
When TDD?
- Helpful for making sure you didn't add new code that is not covered by a test.
- Great for covering edge cases: Found a bug? A use-case you didn't think about? Add a failing test and make it pass.
- Not right for everything: It's not necessarily the right tool for the job if you're prototyping, creating a POC, or working on a research task. Use common sense.
Types of Tests
Integration tests
Test the interaction from the end user's point of view. In our case, we will use Puppeteer to control a browser and interact with our app.
Unit tests
Test specific modules in isolation. Great for covering a lot of different permutations that can take longer with integration tests.
Unit tests: "Looks like it's working"
Component tests
Test a specific component in an environment that emulates a real browser (JSDOM). Great for testing different permutations in a component.
Write tests. Not too many. Mostly integration.
Guillermo Rauch - https://twitter.com/rauchg/status/807626710350839808
Tools
- Puppeteer: A Node.js library that provides an API for controlling a browser.
- JSDOM: JavaScript implementation of many browser APIs that emulate a browser environment in a Node.js process.
- Jest: JavaScript testing framework.
- Yoshi: A zero-configuration build tool for developing apps in Wix.
Puppeteer
A Node.js library that provides an API for controlling a browser.
JSDOM
JavaScript implementation of many browser APIs that emulate a browser environment in a Node.js process.
Jest
JavaScript testing framework.
Yoshi
A zero-configuration build tool for developing apps in Wix.
Let's code :)
testing workshop
By Ronen Amiel
testing workshop
- 554