python单元测试用例


demo1.py

#!/usr/bin/python
# encoding: utf-8
def hello():
    print "i am in demo1"

def add(x,y):
    return x+y
#可以把测试代码写到main中,这样别的类调用此类时,也不会执行main函数
if __name__=='__main__':
    hello()
    a=10
    b="hello"
    c='''hello1
    hello2
    helllo3
    '''
    d,e,f=5,'world',True
    print a,b,c,d,e,f

test_demo1.py

import unittest
from lesson1.demo1 import add

class MyTestCase(unittest.TestCase):
    def test_add(self):
        x=3
        y=4
        z=add(x,y)
        self.assertEqual(z, 7,'method add test failed')

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM