What needs to be tested?
How extensively do I test?
Are 10 unit tests better than 1 integration test?
Should I write tests even if I'm the only developer?
Do I need E2E tests?
Shouldn't the QA engineer write tests for me?
Codebase size
Team size
(git blame is not enough)
(complexity grows exp.)
Technology
(types? encapsulation? lint?)
Code quality
(refactoring)
$$$
(server is down = millions of $ go to the toilet)
Write test code as you write application code (TDD)
80/20 rule: which 20% of tests will cover 80% of the cases?
Think about testing when you write application code (separation of concerns, DI, service layer, pure functions)
Use tooling - test coverage
Think what code is most crucial
Top to bottom
Is being run the most
Is being used the most
Is complex (math, data processing, async)
Can have edge cases (usually unit tests)
Has a crucial business value (Auth, Payments...)
1 unit = function / class
all else is mocked
Endpoint test => routing + view/serialization
Component test?
Less mocking
Series of endpoint tests
visit a URL => interact => check the result
POST /api/register => POST /api/login => GET /api/kingdom
/login => fill the login form => check that I'm on /kingdom
Usually via external tool (Selenium, Cypress.io, Puppeteer)
Testing against real backend
qa.app.com
Integration tests
Acceptance tests
E2E tests
Unit tests
Nice, but rarely done:)