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()
python基础===单元测试unittest的更多相关文章
- python基础——单元测试
python基础——单元测试 如果你听说过“测试驱动开发”(TDD:Test-Driven Development),单元测试就不陌生. 单元测试是用来对一个模块.一个函数或者一个类来进行正确性检验的 ...
- python-单元测试unittest
目录: 1.unittest.TestCase中常用的断言方法 1.1 subTest子测试 1.2 套件测试 1.3 批量测试单个用例 2. 加载器 2.1加载器协议 2.2.执行器 TestRun ...
- python基础===利用unittest进行测试用例执行的几种方式
利用python进行测试时,测试用例的加载方式有2种: 一种是通过unittest.main()来启动所需测试的测试模块: 一种是添加到testsuite集合中再加载所有的被测试对象,而tests ...
- python的单元测试unittest模块
首先需要导入unittest模块 import unittest import HTMLTestRunner # TestCase 也就是测试用例## TestSuite 多个测试用例集合在一起,就 ...
- python之单元测试unittest
一.unittest主要内容 主要核心部分:test case, test suite, test runner, test fixture 二.实例 my_class.py文件如下: class F ...
- Python的单元测试(一)
title: Python的单元测试(一) author: 青南 date: 2015-02-27 22:50:47 categories: Python tags: [Python,单元测试] -- ...
- Python 单元测试框架系列:聊聊 Python 的单元测试框架(一):unittest
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- 面试题之python基础
基础语法 输入和输出 代码中要修改不可变的数据会出现什么问题,抛出什么异常? 代码不会征程运行,抛出TypeError异常 a = 1,b = 2,不用中间变量交换a和b的值? # 方法1 a = a ...
- python基础系列教程——Python3.x标准模块库目录
python基础系列教程——Python3.x标准模块库目录 文本 string:通用字符串操作 re:正则表达式操作 difflib:差异计算工具 textwrap:文本填充 unicodedata ...
随机推荐
- html5 js canvas中画星星的函数
function drawStar(cxt, x, y, outerR, innerR, rot) { cxt.beginPath(); ; i < ; i++) { cxt.lineTo(Ma ...
- 【bzoj1593】[Usaco2008 Feb]Hotel 旅馆 线段树区间合并
题目描述 奶牛们最近的旅游计划,是到苏必利尔湖畔,享受那里的湖光山色,以及明媚的阳光.作为整个旅游的策划者和负责人,贝茜选择在湖边的一家著名的旅馆住宿.这个巨大的旅馆一共有N (1 <= N & ...
- BZOJ4568:[SCOI2016]幸运数字——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4568 https://www.luogu.org/problemnew/show/P3292 A ...
- HDU 2089 不要62 | 暴力(其实是个DP)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2089 题解: 暴力水过 #include<cstdio> #include<algor ...
- Hadoop Yarn-入门篇
参考并推荐博文:https://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/ 重构根本的思想是将 JobTracker 两个主 ...
- 页面元素的CSS渲染优先级
样式的优先级 多重样式(Multiple Styles):如果外部样式.内部样式和内联样式同时应用于同一个元素,就是使多重样式的情况. 一般情况下,优先级如下:(外部样式)External style ...
- Linq改进
原代码: foreach (var item in pageData) { list.Add(new tn_Manager { UserName = item.UserName, IsAudit = ...
- 删除空格-sed
如下,我需要提取出‘wan’这个字符串.可以发现在‘wan’的前后是有空格,需要将其删除. # lxc list # lxc list | grep lxdbr0 | awk -F "|&q ...
- springboot的application.properties与.yml的区别
现在我们的application.properties文件内容是: server.port=8090 server.session-timeout=30 server.context-path= se ...
- AIDL 简单实现
实现步骤1.建立一个aidl文件,在里面定义好接口,注意里面不能写public修饰符,同接口一样,包名要一致. package com.systemset.aidl; interface ILight ...