diff --git a/docs/latest/contributing/testing.md b/docs/latest/contributing/testing.md index 12eadc693..9d26bc82a 100644 --- a/docs/latest/contributing/testing.md +++ b/docs/latest/contributing/testing.md @@ -7,7 +7,7 @@ You're an engineer. You know how to write code, and writing tests isn't all that different. But do you know why we write tests? Do you know when to write one, or what kind of test to write? How do you know if a test is a _"good"_ test? This -document's goal is to give you the tools you need to make those determiniations. +document's goal is to give you the tools you need to make those determinations. Okay. So why do we write tests? To increase our... :drum:: @@ -21,14 +21,16 @@ Okay. So why do we write tests? To increase our... :drum:: ## Kinds of Tests Test's buy us confidence, but not all tests are created equal. Each kind of test -has a different cost to write and maintain. More costly tests +has a different cost to write and maintain. An expensive test is worth it if it +gives us confidance that a payment is processed, but it may not be the best +choice for asserting an element's border color. -| Test Type | Example | Speed | Cost | -| ----------- | ------------------------------------------------------------------------------------------ | ---------------- | ------------------------------------------------------------------------ | -| Static | `addNumbers(1, '2')` was called with a `string`, `int` was expected. | :rocket: Instant | :money_with_wings: | -| Unit | `addNumbers(1, 2)` returns expected result `3` | :airplane: Fast | :money_with_wings::money_with_wings: | -| Integration | When I Click "Sign In", the page navigates to the dashboard (with mocked network requests) | :running: Okay | :money_with_wings::money_with_wings::money_with_wings: | -| End-to-end | When I click "Sign In", the page navigates to the dashboard (with no mocks) | :turtle: Slow | :money_with_wings::money_with_wings::money_with_wings::money_with_wings: | +| Test Type | Example | Speed | Cost | +| ----------- | ------------------------------------------------------------------------ | ---------------- | ------------------------------------------------------------------------ | +| Static | `addNumbers(1, '2')` was called with a `string`, `int` was expected. | :rocket: Instant | :money_with_wings: | +| Unit | `addNumbers(1, 2)` returns expected result `3` | :airplane: Fast | :money_with_wings::money_with_wings: | +| Integration | Clicking "Sign In", navigates to the dashboard (mocked network requests) | :running: Okay | :money_with_wings::money_with_wings::money_with_wings: | +| End-to-end | Clicking "Sign In", navigates to the dashboard (no mocks) | :turtle: Slow | :money_with_wings::money_with_wings::money_with_wings::money_with_wings: | ### Static Code Analysis @@ -39,9 +41,9 @@ with the expected paramater types. Example Tooling: - [ESLint][eslint-rules] -- [TypeScript][typescript-docs] or Flow +- [TypeScript][typescript-docs] or [Flow][flow-org] -Static code analysis can't test business logic. +Where it falls short: Can't test business logic. ### Unit Tests @@ -60,9 +62,13 @@ You're testing implementation details if: - IE. Using a private function - A refactor can break your tests +Where it falls short: That you're calling a dependency appropriately. + ### Integration Tests -... +Integration tests take things one step further. You + +Where it falls short: That you're passing the right data to your backend. ### End-to-End Tests @@ -75,19 +81,36 @@ is testing user authentication. If a user can't sign in to your application, it's an emergency. Having a high degree of confidance that users can always authenticate is very valuable. +Where it falls short: + #### When should we test? -Mission critical features and functionality. Unsure if we should have a test for +Mission critical features and functionality, or to cover a large breadth of +functionality until unit tests catch up. Unsure if we should have a test for feature `X` or scenario `Y`? Open an issue and let's discuss. ## Further Reading +Okay, so hopefully you have more confidance in your understanding of _why_ we +test, and the trade-offs we weigh when determining what kind of test should be +written. For the _how_, check out some of the links below, or read some of the +existing tests in this repository. + +### General + - [Assert(js) Conf 2018 Talks][assert-js-talks] - [Write tests. Not too many. Mostly integration.][kent-talk] - Kent C. Dodds - [I see your point, but…][gleb-talk] - Gleb Bahmutov -- [Statc vs Unit vs Integration vs E2E Testing][kent-blog] - Kent C. Dodds +- [Static vs Unit vs Integration vs E2E Testing][kent-blog] - Kent C. Dodds (Blog) +### End-to-end Testing w/ Cypress + +- [Getting Started](https://docs.cypress.io/guides/overview/why-cypress.html) + - Be sure to check out `Getting Started` and `Core Concepts` +- [Best Practices](https://docs.cypress.io/guides/references/best-practices.html) +- [Example Recipes](https://docs.cypress.io/examples/examples/recipes.html) + @@ -95,6 +118,7 @@ feature `X` or scenario `Y`? Open an issue and let's discuss. [eslint-rules]: https://eslint.org/docs/rules/ [typescript-docs]: https://www.typescriptlang.org/docs/home.html +[flow-org]: https://flow.org/ [assert-js-talks]: https://www.youtube.com/playlist?list=PLZ66c9_z3umNSrKSb5cmpxdXZcIPNvKGw [kent-talk]: https://www.youtube.com/watch?list=PLV5CVI1eNcJgNqzNwcs4UKrlJdhfDjshf