Introduction to unittest - Yasoob Khalid
Hi there folks. I recently thought that I have not written even a single post about testing in python. Testing is one of the most important part of any language. In this post I am going to share some information about unittest with you. So what exactly is unittest? You might have heard about it on StackOverflow or some other forum. It is a testing framework for python just like Junit for Java. It comes pre-installed with python from 2.1. It is easy to use. However there are a lot of other testing frameworks for python out there as well but I will be focusing on unittest today as it is the default testing framework for python. So without wasting any time lets get started. The standard workflow while using unittest is: derive your own class from unittest.TestCase write your tests in functions which start with test_ finally write unittest.main() at the end of your file to run the tests I was also used to be scared by testing. Testing seemed to me as something from outer space but now I have learned its importance and it is essential for every programmer to learn it. A simple script So lets write a simple script which we can later test. This script is going to do some math functions for us. So here is the script: # save it as math.py def multiply(n1, n2): return n1 * n2 def add(n1, n2): return n1 + n2 So thats our little script. Now lets move forward and write our first test. Read the full article




















