Python sample script for unitest with multiple test data's
import unittest
from my_math import product
data = [(2,3,6),(3,3,9),(4,3.5,11)]
class Test(unittest.TestCase):
"""Tests for Product"""
def test_product(self):
try:
for a,b,expected in data:
self.failUnlessEqual(product(a,b),expected,"Product Testcase")
print "Expected is ",expected
except AssertionError:
print "Assertion Error, Check the Values"
if __name__ == "__main__":
unittest.main()
my_math.py file contains:
#__author__ = 'valli'
def product(a,b):
return a*b
import unittest
from my_math import product
data = [(2,3,6),(3,3,9),(4,3.5,11)]
class Test(unittest.TestCase):
"""Tests for Product"""
def test_product(self):
try:
for a,b,expected in data:
self.failUnlessEqual(product(a,b),expected,"Product Testcase")
print "Expected is ",expected
except AssertionError:
print "Assertion Error, Check the Values"
if __name__ == "__main__":
unittest.main()
my_math.py file contains:
#__author__ = 'valli'
def product(a,b):
return a*b
No comments:
Post a Comment