Untitled Document
Unit Test Module - Testing Python Scripts
1. Introduction Click Here
#********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ ***** 
# Introduction

import unittest
import calc

class TestCalc(unittest.TestCase):

	def teest_add(self):
		result = calc.add(10,5)
		self.assertEqual(result, 15)

if __name__ == '__main__':
	unittest.main()
       
2. Program - Adding few more tests Click Here
#********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
# Program - Adding few more tests 

import unittest
import calc

class TestCalc(unittest.TestCase):

	def teest_add(self):
		result = calc.add(10,5)
		self.assertEqual(result, 15)

	def test_sub(self):
		result = calc.subt(10, 2)
		self.assertEqual(result, 7)

	def test_mul(self):
		result = calc.mul(4, 2)
		self.assertEqual(result, 8)


if __name__ == '__main__':
	unittest.main()
       
3. Program - Testing Errors / Exceptions With Context Managers Click Here
#********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
# Program - Testing Errors / Exceptions With Context Managers

import unittest
import calc

class TestCalc(unittest.TestCase):

	def teest_add(self):
		result = calc.add(10,5)
		self.assertEqual(result, 15)

	def test_sub(self):
		result = calc.subt(10, 2)
		self.assertEqual(result, 8)

	def test_mul(self):
		result = calc.mul(4, 2)
		self.assertEqual(result, 8)

	def test_divide(self):
		with self.assertRaises(ValueError):
			calc.divide(10,0)



if __name__ == '__main__':
	unittest.main()


       
Untitled Document