Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Test Driven Development in Python - Customer Comes First

The Customer comes first!

When you're writing code, you should be thinking of your user. That may be your end user or - if you're writing a module or classes - that might be a fellow developer, set of developers or even yourself. Whichever it is, the important thing is to get it right for them. It needs to be well specified, robust, well tested - and that's why you're encouraged to use Test Driven Development.

Writing the tests first helps you ensure that you're providing the right product. It helps you ensure that each of the elements work. And it lets you use testing tools which allow you to build up, rerun and retest time and time again with correlated results. How many times have I written code, come back to it years later and added something in the process breaking an obscure but important feature? With test driven development, and unit test tools, I can now build up test procedures and have an ever-growing validation set. That way, features won't get left behind.

Python coding has always encouraged redientary testing with
  if __name__ == "__main__":
but we can now go further - and we did on yesterday's Intermediate Python course.

My first test code is [here]. It's a simple exercise of an object, with the user having to check the results and ensure that they're as expected.

I extended that [here], testing multiple objects - but still a manual look through the results to ask "was that OK?"

Using unittest [here], I ran a series of tests and they come out with a neat report to show how they've done and

finally [here] I ran a series of tests in severl test groups. And indeed I can keep adding if I wish.

With all working tests, the final results are as short as

  munchkin:yi grahamellis$ python tdd_3
  .....
  ----------------------------------------------------------------------
  Ran 5 tests in 0.001s
  
  OK
  munchkin:yi grahamellis$


which is really all I need.

With a failed test, you get a need log telling you where the issue lies:

  munchkin:yi grahamellis$ python tdd_3
  F....
  ======================================================================
  FAIL: testfinish (__main__.TestBusFunctions)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "tdd_3", line 61, in testfinish
      self.assertEqual(gam,"08:28")
  AssertionError: '08:27' != '08:28'
  
  ----------------------------------------------------------------------
  Ran 5 tests in 0.001s
  
  FAILED (failures=1)
  munchkin:yi grahamellis$


The sample class I was testing through these examples is [here]. You'll note that it's independent of the tests in that there's noting at all that changes in the class for it to be run under the test harness.
(written 2013-05-16, updated 2013-05-18)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q101 - Object Orientation and General technical topics - Programming Principles
  [4645] What are callbacks? Why use them? An example in Python - (2016-02-11)
  [4632] Remember to ask the question before you listen for the answer - (2016-01-26)
  [4611] Hungarian, Camel, Snake and Kebab - variable naming conventions - (2016-01-03)
  [4325] Learning to program - what are algorithms and design patterns? - (2014-11-22)
  [4206] Writing the perfect program in Tcl? - (2013-11-13)
  [4153] Rooms available tonight - how to code an algorithm from first principles - (2013-08-19)
  [4118] We not only teach PHP and Python - we teach good PHP and Python Practice! - (2013-06-18)
  [4061] Seamless, integrated IT - we have a long way to go! - (2013-04-11)
  [4003] Web and console - same principle, same code - Ruby example - (2013-02-14)
  [3954] Lesson 1 in programing - write clean, reuseable and maintainable tidy code - (2012-12-16)
  [3928] Storing your intermediate data - what format should you you choose? - (2012-11-20)
  [3878] From Structured to Object Oriented Programming. - (2012-10-02)
  [3673] Object oriented or structured - a comparison in Python. Also writing clean regular expressions - (2012-03-26)
  [3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
  [3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10)
  [3542] What order are operations performed in, in a Perl expression? - (2011-12-07)
  [3456] Stepping stones - early coding, and writing re-usable code quickly - (2011-09-24)
  [3026] Coding efficiency - do not repeat yourself! - (2010-11-02)
  [2964] An introduction to file handling in programs - buffering, standard in and out, and file handles - (2010-09-21)
  [2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (2010-08-11)
  [2878] Program for reliability and efficiency - do not duplicate, but rather share and re-use - (2010-07-19)
  [2769] Easy - but for whom? - (2010-05-18)
  [2737] Improving your function calls (APIs) - General and PHP - (2010-04-24)
  [2586] And and Or illustrated by locks - (2010-01-17)
  [2550] Do not copy and paste code - there are much better ways - (2009-12-26)
  [2510] The music of the stock market - (2009-11-22)
  [2415] Variable names like i and j - why? - (2009-09-22)
  [2327] Planning! - (2009-08-08)
  [2310] Learning to write high quality code in Lua - (2009-07-30)
  [2228] Where do I start when writing a program? - (2009-06-11)
  [2022] Pre and post increment - the ++ operator - (2009-02-03)
  [2001] I have not programmed before, and need to learn - (2009-01-19)

Q111 - Object Orientation and General technical topics - Programming Security - the considerations.
Y212 - Python - Code testing, patterns, profiles and optimisation.
  [4716] Profiling your Python program - (2016-11-01)
  [4618] Pytest - second example beyond hello world - (2016-01-08)
  [4617] Pytest - starting example - (2016-01-07)
  [4542] The principle of mocking - and the Python Mock package - (2015-10-17)
  [4540] Unittest of a Flask application including forms - (2015-10-15)
  [4538] Flask and unittest - hello web app test world - (2015-10-15)
  [4470] Testing in Python 3 - unittest, doctest and __name__ == __main__ too. - (2015-04-21)
  [4446] Combining tests into suites, and suites into bigger suites - Python and unittest - (2015-03-01)
  [4344] Python base and inherited classes, test harness and unit testing - new examples - (2014-12-07)
  [4326] Learning to program - comments, documentation and test code - (2014-11-22)
  [3658] Using Make for a distribution - (2012-03-17)
  [3478] Testing your Python classes with the unittest package - how to - (2011-10-14)
  [3464] Passing optional and named parameters to python methods - (2011-10-04)
  [3442] A demonstration of how many Python facilities work together - (2011-09-16)
  [3441] Pressing ^C in a Python program. Also Progress Bar. - (2011-09-15)
  [2616] Defining a static method - Java, Python and Ruby - (2010-02-01)
  [2123] Using Python with OpenOffice - (2009-04-09)
  [1555] Advanced Python, Perl, PHP and Tcl training courses / classes - (2008-02-25)
  [1148] Python decorators - wrapping a method call in extra code - (2007-04-15)
  [1146] __new__ v __init__ - python constructor alternatives? - (2007-04-14)
  [1140] Python GTK - Widget, Packing, Event and Feedback example - (2007-04-09)
  [235] Preparation for a day's work - (2005-03-04)


Back to
Quick and easy - showing Python data hander output via a browser
Previous and next
or
Horse's mouth home
Forward to
A reminder of why we opened Well House Manor for our customers
Some other Articles
Python Properties - how and why
More things to make sure that we do NOT do ...
Identity in Python
A reminder of why we opened Well House Manor for our customers
Test Driven Development in Python - Customer Comes First
Quick and easy - showing Python data hander output via a browser
Some tips and techniques for huge data handling in Python
Python network programming - new FTP and socket level examples
Cacheing class for Python - using a local SQLite database as a key/value store
JSON from Python - first principles, easy example
4722 posts, page by page
Link to page ... 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 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2017: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4090_Tes ... First.html • PAGE BUILT: Sat Jun 11 12:16:26 2016 • BUILD SYSTEM: WomanWithCat