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