一个面向对象的测试框架。

pitest的Python项目详细描述


Build status

一个面向对象的测试框架。

安装

来自PIP3:

$ pip3 install --upgrade rstcheck

来源:

$ python3 setup.py --quiet install

测试

先安装pitest软件包,然后:

$ cd unittests
$ python3 -m unittest

用法示例

  1. 编写测试用例:
importpitestclassMyTestCase(pitest.TestCaseBase):# By default, test methods are methods whose names start with 'test_'. You# can change the matching patterns by defining the 'test_patterns' class# variable by uncommenting the following line:#       test_patterns = [ 'mytest_*', 'yourtest_*' ]# The start * means it matches anything, just like the command line glob.# If test methods have inter-dependencies, i.e., certain tests must precede# some other tests, you can define the dependencies using the# 'internal_deps' class variable. Here is an example:#       internal_deps = { 'test_foo1': [ 'test_bar1*', 'test_bar2*' ],#                         'test_hel*lo': [ 'test_no', 'test_yes*' ],#                       }# If this test case depend on other test cases, you can specify their# dependencies via the 'deps' class variable. Here is an example:#       deps = [ 'MyTestCase1', 'MyTestCaseFoo*', ]# When you reference other test cases, you do NOT need to import the files# that define the referenced test cases. But if they cannot be found by the# end of the day, error will occur.def__init__(self[,*args[,**kwargs]]):pass# Run once before running all test methods.defsetup_instance(self[,*args[,**kwargs]]):pass# Run once after running all test methods.defteardown_instance(self[,*args[,**kwargs]]):pass# Run once before running every single test method.defsetup(self[,*args[,**kwargs]]):pass# Run once after running every single test method.defteardown(self[,*args[,**kwargs]]):pass# Actual test methods, names matching 'test_patterns'.deftest_foo_something(self[,*args[,**kwargs]]):passdeftest_foo_something_else(self[,*args[,**kwargs]]):passdeftest_bar_something(self[,*args[,**kwargs]]):passdeftest_bar_something_else(self[,*args[,**kwargs]]):pass
  1. 写入参数文件
importpitest__pitest_main_default_args_name__='my_args'my_args=pitest.TestCaseArgs()my_args.set_method_args('__init__',args=('Anndee',),kwargs={'kwarg0':'KoolArg'})my_args.set_method_args('test',args=('naathing',),kwargs={'kwarg1':'at owl'})my_args2=pitest.TestCaseArgs()my_args2.set_method_args('__init__',args=('Bashii',),kwargs={'kwarg0':'KoolArg2'})my_args2.set_method_args('test',args=('naathing',),kwargs={'kwarg1':'at owlll'})
  1. 运行测试用例

发现测试:

$ python3 -m pitest discover (case | method | all)

运行测试:

$ python3 -m pitest run (case | method) name

扫描给定目录:

$ python3 -m pitest --start-dir some/dir ...

使用动态参数运行测试:

$ python3 -m pitest run case MyTestCase --args-file my_args.py

在文件中使用非默认参数对象:

$ python3 -m pitest run case MyTestCase --args-file my_args.py \
                                        --args-name my_args2

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在Spring Boot 2.2.0中添加弹性搜索?   jakarta ee如何在没有java认证的情况下停止直接访问网页(自定义标记)   java Hibernate:使用executeUpdate()的批删除未清除一级缓存   java如何在Hibernate中插入外键定义为Long的实体?   带参数的java Mockito单元测试计算器方法   java如何从Rally Rest API读取集合属性   java如何对基于消息的处理执行集成测试?   带插入排序的java排序字符串数组标记,双链表   java为什么在基于注释的Spring app@Value默认值中解析为null?   java Apache Commons Http客户端注册特定于客户端的协议   如何使用java反转字符串中n个部分的n个字符   java Tomcat在本地主机上运行良好,但在部署时出现内部服务器错误   使用信号量的变量的java结果   Java编译/运行时类路径问题   java哪个提供商负责AES/CTR/NOP添加?   伪错误解码器中的java响应未获取Zalando问题自定义属性