Showing posts from September, 2017

Unit Test in Python

Python Unit Test is something you will encounter in your intermediate term of python journey, Its good practice to follow unit test as it allows you to test a single unit of logic. I am not going into too much depth of advantage and disadvantages of unit test and why you should use it, you can find many more posts on the topic. My focus here to show you some real code quickly which helps you to build a quick understanding of the topic. Following is the simple program we will be using to see unit test in reality. Just go through it and I will provide a quick explanation of steps. Detailed step by step explanation exist at the end of this post.
#!/usr/bin/env python class Calculate:     def add(self, x, y):         return x + y
if __name__ == '__main__':     calc = Calculate()     result = calc.add(2,3)     print result

Unit test Part: First import unit test libraries import unittest
Then import your program: from calc import Calculator
Now you need to create a class say and override with `uni…