Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to module 5: Testing your Code #147

Merged
merged 4 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions module05_testing_your_code/05_00_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction"
"## Introduction\n",
"\n",
"As we write code, we want to be sure that it does behaves the way we'd like it to - so we test it. Testing (and re-testing) our code is something that needs to be done regularly (ideally after every change to the code), comprehensively, quickly and reliably. In short testing is an task that is ideally suited to automation. \n",
"\n",
"We write additional code to test the behaviour for our main code. We use these terms to distinguish between the two types of code:\n",
"\n",
"* \"Production code\" - the code that fulfills the purpose of the software, and is run by the end user.\n",
"* \"Test code\" - additional code only used by software development team\n",
"\n",
"**For this module we are focusing on _automated testing_.**"
]
},
{
Expand Down Expand Up @@ -63,18 +72,14 @@
"source": [
"### Not a panacea\n",
"\n",
"> Trying to improve the quality of software by doing more testing is like trying to lose weight by\n",
"> weighting yourself more often.\n",
" - Steve McConnell"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" * Testing won't corrrect a buggy code\n",
" * Testing will tell you were the bugs are...\n",
" * ... if the test cases *cover* the bugs"
"> \"Trying to improve the quality of software by doing more testing is like trying to lose weight by\n",
"> weighting yourself more often.\" - Steve McConnell\n",
"\n",
"* Testing won't correct a buggy code\n",
"* Testing will tell you were the bugs are...\n",
"* ... if (and only if) the test cases *cover* the scenarios that cause the bugs or occur.\n",
"\n",
"Also, automated tests only test a narrow interpretation of quality software development. They do *not* help test that your software is _useful_ and help solves a users' problem. We will touch on this again in Module 06.\n"
]
},
{
Expand All @@ -83,15 +88,15 @@
"source": [
"### Tests at different scales\n",
"\n",
"Level of test | Area covered by test\n",
"----------------------- | ---------------------------------------------------------\n",
"**Unit testing** | smallest logical block of work (often < 10 lines of code)\n",
"**Component testing** | several logical blocks of work together\n",
"**Integration testing** | all components together / whole program\n",
"Level of test | Area covered by test | Notes\n",
"----------------------- | --------------------------------------------------------- | ---------------------\n",
"**Unit testing** | smallest logical block of work (often < 10 lines of code) | Unit tests should run fast (eg ~1/100th sec) so that they can be re-run regularly (eg every git commit). To achieve this they should not invoke network access or substantial disk access. \n",
"**Component testing** | several logical blocks of work together | These can be useful where you need to tease out the expected/useful behaviour of 3rd party libraries.\n",
"**Integration testing** | all components together / whole program | These can take longer to run, and can be run less often.\n",
"\n",
"\n",
"* Always start at the smallest scale! \n",
"* If a unit test is too complicated, go smaller."
"* When writing new code (see below) always start by creating tests at the smallest scale (unit tests). \n",
"* If a unit test is too complicated to write, then consider adjusting your production code (possibly by breaking it down into smaller, individually testable functions). Ensuring that your production code is easy to test is a healthy habit."
]
},
{
Expand Down Expand Up @@ -167,7 +172,7 @@
"display_name": "Testing Basics"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.10.0 64-bit ('3.10.0')",
"language": "python",
"name": "python3"
},
Expand All @@ -181,7 +186,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.10.0"
},
"vscode": {
"interpreter": {
"hash": "44f733b714c696d9811e1e4790628c0e5019891ced3dbb8112bc5b951948cffb"
}
}
},
"nbformat": 4,
Expand Down
Loading