{"id":19935096,"url":"https://github.com/optimizely/unit-testing-training","last_synced_at":"2025-05-03T12:30:59.043Z","repository":{"id":71780625,"uuid":"53173897","full_name":"optimizely/unit-testing-training","owner":"optimizely","description":null,"archived":true,"fork":false,"pushed_at":"2016-03-05T00:50:54.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":130,"default_branch":"master","last_synced_at":"2025-03-01T12:17:15.601Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/optimizely.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-03-05T00:16:33.000Z","updated_at":"2023-09-22T18:37:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"be4a3859-ce7c-4ddc-a56b-b8a90167f11e","html_url":"https://github.com/optimizely/unit-testing-training","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Funit-testing-training","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Funit-testing-training/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Funit-testing-training/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Funit-testing-training/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/optimizely","download_url":"https://codeload.github.com/optimizely/unit-testing-training/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252190665,"owners_count":21708922,"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","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":[],"created_at":"2024-11-12T23:18:46.730Z","updated_at":"2025-05-03T12:30:59.035Z","avatar_url":"https://github.com/optimizely.png","language":"Python","readme":"# unit-testing-training\n\nThis repo provides a Python module (`functions.py`) and a corresponding module (`functions_test.py`) containing unit\ntests for `functions.py`.\n\n## Setup\n\nAfter cloning this repo:\n\n```\ngit clone git@github.com:optimizely/unit-testing-training.git\n\ncd unit-testing-training\n```\n\n... run the shell script to install dependencies and create a virtualenv (this will ask for your system password):\n\n```\n./setup.sh\n```\n\nThen enter your new virtualenv:\n\n```\nsource .virtualenv/bin/activate\n```\n\nAnd finally run all the Python tests in this repo:\n\n```\npython -m unittest discover\n```\n\n## Where To Start\n\nTry breaking one of the tests and rerunning the tests. In `functions.py`, change:\n\n```\ndef add_three_to_value(value):\n  return value + 3\n```\n\nto\n\n```\ndef add_three_to_value(value):\n  return value + 4\n```\n\nThen once again run:\n\n```\npython -m unittest discover\n```\n\nAnd you should see something like:\n\n```\n======================================================================\nFAIL: test_add_three_to_value__with_seven (test_my_functions.MyFunctionsTest)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"/Users/username/repos/unit-testing-training/test_my_functions.py\", line 15, in test_add_three_to_value__with_seven\n    self.assertEqual(10, my_functions.add_three_to_value(7))\nAssertionError: 10 != 11\n\n======================================================================\nFAIL: test_add_three_to_value__with_ten (test_my_functions.MyFunctionsTest)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"/Users/username/repos/unit-testing-training/test_my_functions.py\", line 18, in test_add_three_to_value__with_ten\n    self.assertEqual(13, my_functions.add_three_to_value(10))\nAssertionError: 13 != 14\n\n----------------------------------------------------------------------\nRan 6 tests in 0.002s\n\nFAILED (failures=2)\n```\n\nHopefully that helps makes the setup a bit more concrete. Fiddle freely with the tests!\n\n## More Reading/Viewing\n\n* Rambling presentation on unit testing using this repo: https://drive.google.com/a/optimizely.com/file/d/0B3DMe9ZATniSWnZqdHdFQ3J1T0E/view?usp=sharing\n* https://docs.python.org/2/library/unittest.html\n* https://docs.python.org/3/library/unittest.mock.html\n* https://www.toptal.com/python/an-introduction-to-mocking-in-python\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Funit-testing-training","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foptimizely%2Funit-testing-training","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Funit-testing-training/lists"}