Python-3.4.3/C4/Testing-and-Debugging/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:01 Welcome to the spoken tutorial on Testing and debugging.
00:06 In this tutorial, you will, Understand what is software testing
00:11 Test simple functions for their functionality
00:15 Automate tests
00:17 Understand the need for coding style and Learn some of the standards followed by the Python Community
00:25 To record this tutorial, I am using

Ubuntu Linux 16.04 operating system

00:32 Python 3.4.3
00:35 IPython 5.1.0 and Gedit text editor
00:42 To practise this tutorial, you should know how to use functions.
00:48 If not, see the relevant Python tutorials on this website.
00:53 First we will learn about software testing.
00:57 Software testing is the process to evaluate the functionality of a software or a program.
01:04 It helps to find whether the program met the specified requirements or not.
01:10 It ensures a defect free program so that we will get a quality program.
01:16 All the codes used in this tutorial are available in the Code Files link of this tutorial.
01:23 You should download in the current working directory and use them.
01:28 Open any text editor and type the following code.
01:33 This is a simple function to calculate gcd of two numbers.
01:38 We need a set of inputs for the variable a and b.
01:43 Save the file as find underscore gcd.py in the current working directory.
01:50 Next we will open the file test underscore gcd.py.
01:56 Let our test case be 48 and 64 as a and b.
02:02 For this test case we know that the GCD is 16. So that is the expected output.
02:11 Let us now run the script and test our code.
02:15 Open the terminal and type python3 test underscore gcd.py
02:24 We get the output as Test Passed which means our code is correct.
02:30 But there can be a number of cases where the gcd function might break.
02:36 So, to check where our code is breaking we should run many tests.
02:42 This is where the concept of automating tests comes in.
02:46 Let us first try and automate tests on the gcd function.
02:51 Open the file textcases.txt where the various testing parameters are given.
02:58 The structure of the file will have two input parameters.
03:03 The third parameter is the correct output result. We have separated the elements by a space.
03:11 Next let us open the file automate underscore test underscore gcd.py
03:18 First we need import gcd function from find underscore gcd in order to use it for testing.
03:26 Next the testcases.txt file is read line by line.
03:32 The first two input parameters are assigned to the variables x and y.
03:38 The third parameter which is the correct output value is assigned to the variable result.
03:44 We check whether the value returned by the gcd function is equal to the value in the variable result.
03:52 Finally it prints the message accordingly.
03:56 In the terminal, type python3 automate underscore test underscore gcd.py
04:05 As you can see, all the three test cases in testcases.txt are passed.
04:12 The value calculated by the gcd function is equal to the output value provided in the testcases.txt.
04:20 Pause the video. Try this exercise and then resume the video.
04:26 For the same inputs as gcd write automated tests for LCM.
04:33 Use the data from the file lcmtestcases.txt
04:38 Switch to the terminal for the solution.
04:42 Let us see the code to calculate lcd of two numbers.

The file name is find underscore lcm.py

04:52 This is the data file for the lcm test cases.
04:57 This file name is lcmtestcases.txt
05:02 Note that both these files should be in the current working directory.
05:07 Let us now run the script and test our code.
05:11 Type python3 find underscore lcm.py
05:17 Here, the third test case failed. Because the corresponding input in lcmtestcases.txt is incorrect.
05:26 This is to check the behavior of the program on incorrect conditions.
05:32 A good program should be readable. So others can extend and improve it.
05:39 Code is read more often than it is written.
05:43 We choose a name so that it becomes easier to understand its usage.
05:49 As we can see in the example, it is very easy to understand what the code is doing.
05:55 Proper naming helps so much in understanding the code.
06:00 Also one should keep in mind the following things while writing a code in Python.
06:06 Four Space Indentation
06:09 79 characters limit on a line
06:13 Functions and methods should be separated with two blank lines.
06:18 Use Docstring to document a specific segment of code.
06:23 Use whitespace around operators and after punctuations.
06:28 This brings us to the end of this tutorial. Let us summarize.
06:34 In this tutorial, we have learnt to,

Create simple tests for a function

06:40 Automate tests using many predefined test cases and Use python coding standards.
06:49 Here is a self assessment question for you to solve
06:53 What is the proper indentation for python code according to the style guidelines?
06:59 And the answer, Four Space Indentation is required for writing a python code according to the style guidelines.
07:08 Please post your timed queries in this forum.
07:12 Please post your general queries on Python in this forum.

FOSSEE team coordinates the TBC project.

07:22 Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India. For more details, visit this website.
07:33 This is Priya from IIT Bombay signing off. Thanks for watching.

Contributors and Content Editors

PoojaMoolya