1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
.. Objectives
.. ----------
.. At the end of this tutorial, you will be able to:
.. 1. Know what is TDD.
.. 2. Understand the use of test cases.
.. 3. Write simple tests for a function.
.. Prerequisites
.. -------------
.. 1. Getting started with functions
Script
------
.. L1
{{{ Show the first slide containing title, name of the production
team along with the logo of MHRD }}}
.. R1
Hello friends and Welcome to the tutorial on
'Test driven development - Part 1'.
.. L2
{{{ Show slide with objectives }}}
.. R2
At the end of this tutorial, you will be able to,
1. understand basics of Test Driven Development.
#. understand the use test cases.
#. write simple tests for a function.
.. L3
{{{ Switch to the slide3, pre-requisite slide }}}
.. R3
Before beginning this tutorial,we would suggest you to complete the
tutorial on "Getting started with functions".
.. R4
Test-driven development is a software development
process that relies on the repetition of a very short
development cycle.
In TDD,one writes a failing automated test case that
defines a desired improvement or new function, then produces
code to pass that test and finally refactors the new code to
acceptable standards.
.. L4
{{{ Switch to slide4 ,What is TDD?}}}
.. R5
To illustrate TDD, lets take a simple program. Consider a
function ``fibonacci``, that takes one argument and returns
the nth number of ``fibonacci`` series.
.. L5
{{{ Switch to slide5, First test- fibonacci }}}
.. R6
To test ``fibonacci`` function, we need test
cases.
As shown in this slide,
test cases are expected outputs for a given set of inputs.
.. L6
{{{ Switch to slide6, Test cases }}}
.. R7
The sample code for test cases is shown here. Observe that if
any ``if`` statement is executed, test aborts after printing the
error message.
.. L7
{{{ Switch to slide7, Test cases-Code }}}
.. R8
The ``fibonacci`` function is written just enough so that
test can run.
.. L8
{{{ switch to slide8, Stubs }}}
.. R9
Combine the function and test cases and put them together in
``fibonacci.py`` file.Add the test cases after name=main idiom.
.. L9
{{{ Switch to slide9, fibonacci.py }}}
.. R10
Lets run fibonacci.py by typing ``python fibonacci.py``.
As we haven't written any meaningful code in our ``fibonacci``
function, it fails immediately.
Our next step is to write just minimum code to pass our tests.
.. L10
{{{ Run the fibonacci.py in terminal and show the error output.}}}
::
python fibonacci.py
.. R11
Modify the fibonacci stub function with given code.
Save and run it again as `` python fibonacci.py``.
{{{ pause }}}
Observe that, there will be no errors, as
the test passes successfully.
.. L11
{{{ switch to slide-11, Euclidean Algorithm }}}
Switch to terminal and modify fibonacci function in ``nano``
editor and run.
::
python fibonacci.py
.. R12
The same ``fibonacci`` function is modified to make it more readable
and easy to understand using recursion.
Pause this video here.Replace the ``fibonacci`` function with recursive one.
Run the modified ``fibonacci.py`` file. The test should pass again
without any errors.
After successfully achieving this result, you can resume the video.
.. L12
{{{ Show slide12, Euclidean Algorithm- Recursive}}}
.. R13
This brings us to the end of the tutorial.In this tutorial,
we have learnt to,
1. Undestand the basic steps involved in Test driven development.
#. Design a Test driven approach for a given ``fibonacci`` function.
.. L13
{{{ switch to slide-13,Summary }}}
.. R14
Here are some self assessment questions for you to solve
1.
2.
.. L14
{{{ switch to slide-14, Evaluation }}}
.. R15
And the answers are,
1.
2.
.. L15
{{{ switch to slide-15 ,Solutions}}}
.. R16
Hope you have enjoyed this tutorial and found it useful.
Thank you!
.. L16
{{{ Switch to slide-16, Thankyou}}}
|