{"id":16120354,"url":"https://github.com/nadvolod/testing-best-practices","last_synced_at":"2025-09-14T23:58:44.462Z","repository":{"id":50723087,"uuid":"354298535","full_name":"nadvolod/testing-best-practices","owner":"nadvolod","description":"A place to capture testing best practices that are curated by industry's best so that we can all do better testing🚀","archived":false,"fork":false,"pushed_at":"2024-02-20T15:02:29.000Z","size":93,"stargazers_count":16,"open_issues_count":0,"forks_count":7,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-02T15:11:13.791Z","etag":null,"topics":["hacktoberfest","hacktoberfest2021","test","testing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nadvolod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-03T13:25:23.000Z","updated_at":"2025-03-30T01:52:53.000Z","dependencies_parsed_at":"2024-10-27T18:12:08.978Z","dependency_job_id":"149be076-febe-44b3-b37a-c81385c577fc","html_url":"https://github.com/nadvolod/testing-best-practices","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nadvolod/testing-best-practices","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadvolod%2Ftesting-best-practices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadvolod%2Ftesting-best-practices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadvolod%2Ftesting-best-practices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadvolod%2Ftesting-best-practices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nadvolod","download_url":"https://codeload.github.com/nadvolod/testing-best-practices/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadvolod%2Ftesting-best-practices/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275185376,"owners_count":25419919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","hacktoberfest2021","test","testing"],"created_at":"2024-10-09T20:58:01.081Z","updated_at":"2025-09-14T23:58:44.412Z","avatar_url":"https://github.com/nadvolod.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# testing-best-practices\nThere are so many amazing testing resources on the web but they are all disorganized. What if there was a single place that used the information from these resources to create testing best practices for the world? Furthermore, each testing recommendation would be evaluated by a team of industry leaders to ensure that the practice makes sense. Testing Best Practices is that single source of truth for how to test all the relevant tech in the world.\n\n## `Table of Contents`\n\n### [`What is a good test?`](#what-is-a-good-test)\n### [`General testing rules`](#general-rules-of-testing)\n### [`Testing Web Applications`](#testing-web-applications)\n* [Testing a button](#testing-a-button)\n* [Testing a link](#testing-a-link)\n* [Testing CAPTCHA](#Testing-a-CAPTCHA)\n### [`Best Resources To Learn Testing`](#best-resources-to-learn-testing)\n### [`X: React Testing Library`](#section-)\n\n# What is a good test?\n\n[These properties were originally proposed by Kent Beck](https://medium.com/@kentbeck_7670/test-desiderata-94150638a4b3)\n\n* Isolated — tests should return the same results regardless of the order in which they are run.\n* Composable — if tests are isolated, then I can run 1 or 10 or 100 or 1,000,000 and get the same results.\n* Fast — tests should run quickly.\n* Inspiring — passing the tests should inspire confidence\n* Writable — tests should be cheap to write relative to the cost of the code being tested.\n* Readable — tests should be comprehensible for reader, invoking the motivation for writing this particular test.\n* Behavioral — tests should be sensitive to changes in the behavior of the code under test. If the behavior changes, the test result should change.\n* Structure-insensitive — tests should not change their result if the structure of the code changes.\n* Automated — tests should run without human intervention.\n* Specific — if a test fails, the cause of the failure should be obvious.\n* Deterministic — if nothing changes, the test result shouldn’t change.\n* Predictive — if the tests all pass, then the code under test should be suitable for production.\n\n# General rules of testing\n\n## Retries\n\n✅ **Do**: Only use retries when the cause of indeterminism is fully understood and is unavoidable\n\nWhat is **unavoidable indeterminism**?\n* Internet instability (or maybe we can mock this out)\n* 3rd party Selenium Grid going down\n* 3rd party service going down (or can we mock this out)\n\n❌ **Otherwise**: We are simply putting a bandaid on instability and will pay for it later, either in the app or the build\n\n\u003cbr/\u003e\n\u003cdetails\u003e\u003csummary\u003e© \u003cb\u003eCredits \u0026 read-more\u003c/b\u003e\u003c/summary\u003e\n  1. \u003ca href='https://www.linkedin.com/feed/update/urn:li:activity:6803741817750855680/'\u003eJonathan Lipps, Appium creator\u003c/a\u003e\n\u003c/details\u003e\n\n\u003cbr/\u003e\u003cbr/\u003e\n\n\n# Testing Web Applications\n\nThe modern web application typically runs on some type of JavaScript framework such as Angular, React, or Vue. A guiding principle of testing such web applications is to think about how we can do so without an actual browser. In many cases, a combination of component, unit, and visual tests will be the most powerful in ensuring quality web applications.\n\n\n## Testing a button\n\n✅ **Do**: Use a component test with a virtual DOM instead of an actual browser\n\n\n❌ **Otherwise**: Extra dependencies will create more complications and work, with no added benefit:\n\n⚠️ Need a browser\n\n⚠️ Need a server\n\n⚠️ Need to deal with network issues\n\n⚠️ Test will be slower\n\n⚠️ Need an extra dependency (Cypress/Selenium...)\n\n⚠️ Need to learn extra dependency API\n\n\u003cdetails\u003e\u003csummary\u003e✏ \u003cb\u003eCode Examples\u003c/b\u003e\u003c/summary\u003e\n  \n\u003cbr/\u003e\n  \n### :clap: Doing It Right Example: A button should be tested with a component test\n\n\n```javascript\n// App.js - the button being tested\nfunction App() {\n  const [buttonColor, setButtonColor] = useState('red');\n  const newButtonColor = buttonColor === 'red' ? 'blue' : 'red';\n  return (\n    \u003cdiv\u003e\n      \u003cbutton \n        style={{backgroundColor: buttonColor}}\n        onClick={() =\u003e setButtonColor(newButtonColor)}\u003e\n          Change to {newButtonColor} \n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n\n```\n\n**Expected Behaviors**\n1. Button starts in 'red' state\n2. Button starts with text that says \"Change to blue\"\n3. On click, button changes color to 'blue'\n4. On click, button changes text that says \"Change to red\"\n\n```javascript\nimport { render, screen, fireEvent } from '@testing-library/react';\nimport App from './App';\n\ntest('should start in red state', () =\u003e {\n  //render the component in a virtual DOM\n  render(\u003cApp /\u003e);\n  //find an element with a role of button and text\n  const button = screen.getByRole('button', {name: 'Change to blue'})\n  //expect the background color to be red\n  expect(button).toHaveStyle({backgroundColor: 'red'})\n});\n\ntest('should change color to blue on click', () =\u003e {\n  //render the component in a virtual DOM\n  render(\u003cApp /\u003e);\n  //find an element with a role of button and text\n  const button = screen.getByRole('button', {name: 'Change to blue'})\n  //click button\n  fireEvent.click(button);\n  //expect the background color to be blue after click\n  expect(button).toHaveStyle({backgroundColor: 'blue'})\n  //check that text is changed to 'Changed to red'\n  expect(button.textContent).toBe('Change to red')\n})\n```\n\n\u003cbr/\u003e\n\n\u003c/details\u003e\n\n\u003cbr/\u003e\n\u003cdetails\u003e\u003csummary\u003e© \u003cb\u003eCredits \u0026 read-more\u003c/b\u003e\u003c/summary\u003e\n  1. \u003ca href='https://github.com/nadvolod/js-code/blob/1b6b15a79349748a40fc630d4d8de699ffd50780/testing-js/react-components/test-app/src/App.test.js#L4'\u003eNikolay Advolodkin - testing a button component\u003c/a\u003e\n\u003c/details\u003e\n\n\u003cbr/\u003e\u003cbr/\u003e\n\n## Testing a link\n\n✅ **Do**: Use a component test with a virtual DOM instead of an actual browser.\n\nAvoid clicking a link as the clickability of `\u003ca\u003e` is a default browser behavior and not the behavior of our SUT (Software Under Test).\n\n❌ **Otherwise**: Extra dependencies will create more complications and work, with no added benefit. Same problems as a button test.\n\n\u003cdetails\u003e\u003csummary\u003e✏ \u003cb\u003eCode Examples\u003c/b\u003e\u003c/summary\u003e\n  \n\u003cbr/\u003e\n  \n### :clap: Doing It Right Example: A link should be tested with a component test by \n\n**SUT**\n\n```javascript\n// App.js - the link being tested\nfunction App() {\n  return (\n    \u003cdiv className=\"App\"\u003e\n      \u003cheader className=\"App-header\"\u003e\n        \u003cimg src={logo} className=\"App-logo\" alt=\"logo\" /\u003e\n        \u003cp\u003e\n          Edit \u003ccode\u003esrc/App.js\u003c/code\u003e and save to reload.\n        \u003c/p\u003e\n        \u003ca\n          className=\"App-link\"\n          href=\"https://www.ultimateqa.com\"\n          target=\"_blank\"\n          rel=\"noopener noreferrer\"\n          data-testid=\"learn-link\"\n        \u003e\n          Learn Testing with Mia\n        \u003c/a\u003e\n      \u003c/header\u003e\n    \u003c/div\u003e\n  );\n}\n\n```\n\n**Rendered View**\n\n**Expected Behaviors**\n1. Link goes to \"https://www.ultimateqa.com\"\n2. Link opens in new tab\n\n```javascript\ntest('link has correct url', () =\u003e {\n  //render our App component in a virtual DOM\n  render(\u003cApp /\u003e);\n  //get the link element by data-testid\n  const linkElement = screen.getByTestId('learn-link')\n  //assert that the href is correct\n  expect(linkElement.href).toContain('ultimateqa.com');\n})\n\ntest('link opens in new tab', () =\u003e {\n  //render our App component in a virtual DOM\n  render(\u003cApp /\u003e);\n  const linkElement = screen.getByText('Learn Testing with Mia')\n  //Link should open a new tab\n  expect(linkElement.target).toBe('_blank')\n})\n```\n\n\u003cbr/\u003e\n\n\u003c/details\u003e\n\n\u003cbr/\u003e\n\u003cdetails\u003e\u003csummary\u003e© \u003cb\u003eCredits \u0026 read-more\u003c/b\u003e\u003c/summary\u003e\n  1. \u003ca href='https://github.com/saucelabs-training/automation-best-practices/blob/main/my-react-app/FULL-COVERAGE.md#why-is-this-test-bad'\u003eAutomation Best Practices workshop\u003c/a\u003e\n\u003c/details\u003e\n\n\u003cbr/\u003e\u003cbr/\u003e\n\n\n\n## ⚪ ️ Testing a CAPTCHA\n\nCAPTCHA is short for \"Completely Automated Public Turing test to tell Computers and Humans Apart.\" It exists to prevent automation, so it's not even worth trying. Otherwise, it fails to be CAPTCHA, because it won’t be able to tell humans and computers apart ([Selenium.dev](https://www.selenium.dev/documentation/en/worst_practices/captchas/)).\n\nTwo primary strategies exist to get around CAPTCHA checks during testing. They are as follows:\n\n* Disable CAPTCHAs in your test environment. This could be a simple configuration in the software under test. Or this can even be a URL parameter that the test sets. Example: `www.software.com/?disableCaptcha`\n* Add a hook to allow tests to bypass the CAPTCHA.\n\n([10 testing scenarios you should never automate with Selenium. TechBeacon.com](https://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium))\n\n## ⚪ ️ Doing visual testing by large scale element identification\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\n\n## ⚪ ️ Two-factor authentication\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\n\n## ⚪ ️ File downloads\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\n\n## ⚪ ️ HTTP reponse codes\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\n\n## ⚪ ️ Gmail, email, and Facebook logins\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\n\n## ⚪ ️ Stress or load testing\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\n\n## ⚪ ️ Testing links\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\nhttps://github.com/saucelabs-training/automation-best-practices/blob/9cea9cb0af39de3adc91dd42e89d68a9a1a5df96/my-react-app/src/__tests__/Solution.test.js#L16\n\n## ⚪ ️ Testing video streaming\n\nhttps://techbeacon.com/app-dev-testing/10-testing-scenarios-you-should-never-automate-selenium\n\n## ⚪ ️ Testing tabs\n\nhttps://github.com/saucelabs-training/automation-best-practices/blob/9cea9cb0af39de3adc91dd42e89d68a9a1a5df96/my-react-app/src/__tests__/Solution.test.js#L25\n\n\n# Best Resources To Learn Testing\n\n## ⚪ ️ Unit testing\n## ⚪ ️ Integration testing\n## ⚪ ️ Component testing\n\u003ca href=\"https://click.linksynergy.com/link?id=fVAbrMnoMS0\u0026offerid=507388.3780436\u0026type=2\u0026murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Freact-testing-library%2F\"\u003eTesting React with Jest and Testing Library (Udemy course)\u003c/a\u003e\u003cIMG border=0 width=1 height=1 src=\"https://ad.linksynergy.com/fs-bin/show?id=fVAbrMnoMS0\u0026bids=507388.3780436\u0026type=2\u0026subid=0\" \u003e\n## ⚪ ️ Acceptance testing\n### ⚪ ️ Browser testing\n  \n### ⚪ ️ Visual testing\n### ⚪ ️ Front-end performance testing\n### ⚪ ️ Back-end performance testing\n### ⚪ ️ Security testing\n\n# X: React Testing Library\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadvolod%2Ftesting-best-practices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnadvolod%2Ftesting-best-practices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadvolod%2Ftesting-best-practices/lists"}