Unit tests check one small piece of code in isolation, integration tests check that several pieces work together (for example code plus a real database), and end-to-end tests drive the whole application the way a user would.
The test pyramid is a guideline to have many fast unit tests at the base, fewer integration tests in the middle and only a small number of slow end-to-end tests at the top, so the suite stays fast and reliable.
Mocking replaces a real dependency with a controllable fake so a test can run in isolation and check how the code interacts with it; use it for slow, non-deterministic or external dependencies, not for everything.
Treat a flaky test as a bug: quarantine it so it stops blocking the pipeline, reproduce it by running it repeatedly, fix the root cause (usually timing, shared state or external dependencies), then bring it back.
Selenium is the long-established, language-agnostic standard built on WebDriver; Cypress runs inside the browser with an excellent developer experience for JavaScript apps; Playwright offers fast, auto-waiting cross-browser automation with multiple tabs, contexts and languages. For a new web project, Playwright is usually the strongest default.