Kent C. Dodds
Utah
wife, 4 kids, & a dog
PayPal, Inc.
if you are able ❤️ ♿️
Fundamentals behind tests and testing frameworks
Distinctions of different forms of testing
Writing unit and integration
Test doubles (mocks/stubs/etc.)
Use TDD to write new features and to find and fix bugs
Core principles of testing to ensure your tests give you the confidence you need
If you can, do it now, even if you've already done it...
git clone https://github.com/kentcdodds/testing-workshop.git
cd testing-workshop
npm run setup --silent
Business Logic 🕷
Security 🕷
Accessibility 🐜
User Interface 🐞
Performance 🐛
Regression 🐞
Internationalization 🕷
Integration 🐜
Scaling 🐛
Unit Testing
Regression Testing
Integration Testing
E2E Testing
Smoke Testing
Usability Testing
i18n Testing
Penetration Testing
User Acceptance Testing
Performance Testing
A/B Testing
a11y Testing
Stress Testing
Fuzz Testing
function sum(a, b) {
return a + b
}
test('sum adds numbers', () => {
expect(sum(1, 3)).toBe(4)
})
let api, server
beforeAll(async () => {
server = await startServer()
const {port} = server.address()
api = axios.create({
baseURL: `http://localhost:${port}/api`
})
})
afterAll(() => server.close())
beforeEach(() => resetDb())
test('can register a user', async () => {
const registerData = {username: 'bob', password: 'wiley'}
const testUser = await api
.post('auth/register', registerData)
.then(response => response.data.user)
expect(testUser.username).toBe(registerData.username)
const readUserUnauthenticated = await api
.get(`users/${testUser.id}`)
.then(response => response.data.user)
expect(readUserUnauthenticated).toEqual(testUser)
})
import {assertRoute} from '../utils'
describe('authentication', () => {
it('should allow users to register', () => {
const user = {username: 'bob', password: 'wiley'}
cy
.visitApp()
.getByText('Register')
.click()
.getByLabelText('Username')
.type(user.username)
.getByLabelText('Password')
.type(user.password)
.getByText('Login')
.click()
cy.url().should('equal', 'http://localhost:3000/')
cy.getByTestId('username-display').should('contain', user.username)
})
})
Red
Green
Refactor
Bug
Find Code
Write Test
Fix Test
¢heap
💰🤑💰
🏎💨
🐢
Simple problems 👌
Big problems 😖
My blog/newsletter has a lot of content about testing too: blog.kentcdodds.com