python3 测试函数的一个例子

文件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

猜你喜欢

转载自blog.csdn.net/digitalkee/article/details/112516989
今日推荐