python基础===单元测试unittest
2024-10-18 22:19:13
'''
编写一个名为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()
最新文章
- YII的Modules模块化
- php 随记
- noip模拟赛 纸壳子
- JS - Cookie: getCookie, setCookie
- js的alert和confirm美化
- Libevent windows/linux下编译
- PAT1003——我要通过!
- gulp基础使用总结
- JS选中OPTION
- Convert boolean values to strings 'Yes' or 'No'.
- Android群英传》读书笔记 (4) 第八章 Activity和Activity调用栈分析 + 第九章 系统信息与安全机制 + 第十章 性能优化
- [Python笔记]第十篇:模块续
- COJ 0342 逆序对(一)
- Eloquent ORM 学习笔记
- android五种布局模式
- JAVA必备——13个核心规范
- 基于百度地图SDK和Elasticsearch GEO查询的地理围栏分析系统(3)-前端实现
- ajax同步与异步的坑
- remote: Permission to user_name/Code.git denied to other_user_name. fatal: unable to access 'https://github.com/user_name/Code.git/': The requested URL returned error: 403
- 调整Eclipse中代码字体字号
热门文章
- 第60天:js常用访问CSS属性的方法
- 在上传文件时候 request.setCharset对文件名有效 对普通文本域无效 需要通过手动转换编码方式编码
- Elasticsearch Query DSL备忘(1)(Constant score query和Bool Query)
- 【题解】Atcoder AGC#03 E-Sequential operations on Sequence
- 【以前的空间】bzoj1009 [HNOI2008]GT考试
- LOJ6354 &; 洛谷4366:[Code+#4]最短路——题解
- php ul li 分类
- Java中的字符串常量池?
- ubuntu 服务器搭建汇总
- lnmp环境不支持require 解决方法