python基础===单元测试unittest

'''
编写一个名为Employee 的类,其方法__init__()接受名、姓和年薪,并
将它们都存储在属性中。编写一个名为give_raise()的方法,它默认将年薪增加5000
美元,但也能够接受其他的年薪增加量。
为Employee 编写一个测试用例,其中包含两个测试方法:test_give_default_
raise()和test_give_custom_raise()。使用方法setUp(),以免在每个测试方法中都创
建新的雇员实例。运行这个测试用例,确认两个测试都通过了。
'''
class Employee():
    def __init__(self, firstname , lastname, money):
        self.firstname = firstname
        self.lastname = lastname
        self.money = money

    def give_reise(self,raise=5000):
        self.money += int(raise)
        return self.money
import unittest
from  Employee import Employee

class EmployeeTestCase(unittest.TestCase):
    def setUp(self):
        '''
        创建新的员工
        '''
        self.new_a = Employee("li", "ming", 700)
        self.new_b = Employee("xiao", "hong", 2000)
        self.new_c = Employee("WWW", "COM", 5000) 

    def test_give_default_raise(self):
        self.new_a.give_reise()
        x = self.new_a.money
        print(x)
        self.assertEqual(x,5700)

    def test_give_custom_reise(self):
        self.new_b.give_reise(1000)
        self.new_c.give_reise(8000)
        self.assertEqual(self.new_b.money, 3000)
        self.assertEqual(self.new_c.money, 13000)



unittest.main()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

软件测试技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值