checkexpect是一个用于python开发的简单单元测试框架
checkexpect的Python项目详细描述
checkexpect是一个简单的python开发单元测试框架https://pypi.python.org/pypi/checkexpect 在python库中。checkexpect是一种成熟、可行的方法,可以让测试驱动的开发驱动数据的设计, 你的数据驱动你的功能设计。它也是一个简单的工具,允许您在内联中执行单元测试 用你的代码,以系统的方式。
这是原始checkexpect的分叉,托管在github和 上次更新时间是2016年。
功能
- [X]支持内联单元测试。checkexpect也将支持在另一个目录中创建的测试。
- [X]支持TDD和DDD开发。
- [X]支持使用HTDD和HTDF配方的系统程序设计方法。
- [X]支持彩色编码终端(控制台)输出。
待办事项
- []支持Python3.5。
安装
安装checkexpect。
pipinstallcheckexpect
现在您可以像这样添加对checkexpect包的引用。
#!/usr/bin/env python# import packagefromcheckexpect.coreimportcheckExpect
编写一些代码并使用checkexpect与代码内联进行测试。
#!/usr/bin/env python# import packagesfromcheckexpect.coreimportcheckExpectimportmath# Usage: checkExpect(function|object|type, param, expected value, "a description of the test")# define a functiondefsquare(a):returna*a# could replace return statement with (lambda a: math.pow(a, 2))# from code_statement_B below.# examplesnum_to_square=12code_statement_A=12*12# used in the function body# check the algor1thm design of our square function, and unit test it at the same timecheckExpect(square,12,144,"Square of a number")# Or just pass our examplescheckExpect(square,num_to_square,code_statement_A,"Square of a number")# Or use lambda expressionscode_statement_B=lambdaa:math.pow(a,2)checkExpect(square,num_to_square,code_statement_B(12),"Square of a number")# add up a list of numbers# examplesparam1=[1,2,9]defadd(args):total=0foriinargs:total=i+totalreturntotalcheckExpect(add,param1,12,"Add two numbers")# Create a string from an arbitrary list of strings# examplesparam3=["Darel","Johnson"]defstring_together(los):newStr=[str.strip()forstrinlos]return" ".join(newStr)checkExpect(string_together,param3,"Darel Johnson")
从命令行(终端)执行python脚本以查看单元测试结果。大多数测试通常在开始时失败(红色)。
重构代码并执行脚本,直到所有正在测试的函数变为绿色。
就这样!你完了。
升级
升级checkexpect。
pipinstallcheckexpect-U
该命令将升级现有的CHECKEVE安装。
许可证
这个项目最初是作为javascript单元测试项目启动的。这个项目是 在2013年被抛弃,并在年被我们的团队重新激活 2016年。在这个过程中,大部分项目都经过了重构并加快了速度。 使用现代python最佳实践。2013年重写之前完成的工作是 麻省理工学院授权。从那以后的改进是由麻省理工学院授权的。 有关详细信息,请参见LICENSE。
Semver
这个项目实现Semantic Versioning。