Difference between revisions of "Python-3.4.3/C4/Testing-and-Debugging/English"
(Created page with "'''Title of script''': '''Testing and debugging''' '''Author: Puneeth, Thirumalesh H S, Arun KP''' '''Keywords: Python, Ipython, testing, debugging, automate test, coding st...") |
|||
Line 329: | Line 329: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We choose a name so that it becomes easier to understand its usage. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We choose a name so that it becomes easier to understand its usage. | ||
− | |||
− | |||
− | |||
Revision as of 13:19, 24 October 2018
Title of script: Testing and debugging
Author: Puneeth, Thirumalesh H S, Arun KP
Keywords: Python, Ipython, testing, debugging, automate test, coding style, python community, video tutorial
Visual Cue | Narration |
Show Slide title | Welcome to the spoken tutorial on Testing and debugging. |
Show Slide
Objectives
|
In this tutorial, you will,
|
Show Slide
System Specifications |
To record this tutorial, I am using
|
Show Slide
Prerequisite |
To practise this tutorial, you should know how to
If not, see the relevant Python tutorials on this website. |
Show Slide
Software Testing
|
First we will learn about software testing.
|
Show slide:
Source code
|
All the codes used in this tutorial are available in the Code Files link of this tutorial.
|
gcd function
def gcd(a, b): if b == 0: return a return gcd(b, a%b) Highlight def gcd(a,b): |
Open any text editor and type the following code.
|
Save the file find_gcd.py | Save the file as find underscore gcd.py in the current working directory. |
Open the file test_gcd.py | Next we will open the file test underscore gcd.py. |
from find_gcd import gcd
result = gcd(48, 64) if result != 16: print("Test failed") print("Test Passed") |
Let our test case be 48 and 64 as a and b.
For this test case we know that the GCD is 16.
|
[Terminal]
|
Let us now run the script and test our code.
|
But there can be a number of cases where the gcd function might break. | |
Slide: Test cases | So to check where our code is breaking we should run many tests.
|
Open the file testcases.txt and show | Let us first try and automate tests on the gcd function.
|
Open testcases.txt
12 28 4 18 36 18 4678 39763 2339 |
The structure of the file will have two input parameters.
|
Open automate_test_gcd.py | Next let us open the file automate underscore test underscore gcd.py |
Highlight the code:
from find_gcd import gcd
for line in open('testcases.txt'): numbers = line.split() x, y = int(numbers[0]) , int(numbers[1]) result = int(numbers[2]) if gcd(x, y) != result: print ("Failed gcd test for", x, y) else: print ("Test passed", result)
|
First we need import gcd function from find underscore gcd in order to use it for testing.
|
In the terminal, type
|
In the terminal, type
|
Point to the output | As you can see, all the three test cases in testcases.txt are passed.
|
Pause the video.
| |
Show Slide
Assignment 1
|
For the same inputs as gcd write automated tests for LCM.
|
Switch terminal | Switch to the terminal for the solution. |
Open the find_lcm.py
|
Let us see the code to calculate lcd of two numbers.
|
Type python3 find_lcm.py | Type python3 find underscore lcm.py |
Open find_lcm.py and show.
|
Here, the third test case failed.
|
Show Slide
Coding Style |
* A good program should be readable.
|
Show Slide
Meaningfull names
|
We choose a name so that it becomes easier to understand its usage.
it is very easy to understand what the code is doing.
|
Show Slide
Coding Instructions |
Also one should keep in mind the following things while writing a code in Python.
|
Show Slide
Code Instructions |
* Use Docstring to document a specific segment of code.
|
Show Slide
Summary |
This brings us to the end of this tutorial. Let us summarize.
In this tutorial, we have learnt to,
|
Show Slide
Self assessment questions |
Here is a self assessment question for you to solve
|
Show Slide Solutions | And the answer,
|
Show Slide Forum | Please post your timed queries in this forum. |
Show Slide Fossee Forum | Please post your general queries on Python in this forum. |
Slide Textbook Companion | FOSSEE team coordinates the TBC project. |
Show Slide
Acknowledgment |
Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.
For more details, visit this website. |
Previous slide | This is Priya from IIT Bombay signing off.
Thanks for watching. |