文件1.py
from fun import find_large
import unittest
#define a inherit class
#father class is unittest.TestCase
#which is a class of unittest
class TestFuntion(unittest.TestCase):
#define a method of the class
#which has one parameter self
def test_large(self):
#calculate a data from outside function which will be tested
large = find_large(12,10)
#use a assert of the class you defined by yourself
self.assertEqual(large,12)
#call the function main() from unittest
unittest.main()
文件fun.py
def find_large(num1,num2):
if num1 >= num2:
return num1
else:
return num2