重复测试框架:助手功能,当同一功能用不同的数据进行多次测试时,减少实现的锅炉板或重复代码的数量。

Repeated-Test-Framework的Python项目详细描述


https://img.shields.io/pypi/v/repeated-test-framework.svghttps://travis-ci.org/TonyFlury/repeatedtestframework.png?branch=masterhttps://codecov.io/github/TonyFlury/repeatedtestframework/coverage.svg?branch=masterhttps://readthedocs.org/projects/repeatedtestframework/badge/?version=latest

简介

重复测试框架设计用于unittest标准库模块(unittest for Python 2.7unittest for Python 3.5),以便 生成针对同一功能的多个测试用例 其中,测试用例之间的差异是不同的测试输入和 不同的预期结果。

功能

框架提供以下功能:

  • Supports Python 2 and Python 3
  • Easy to use
    • Uses a list of dictionaries (or any Iterable of mappings) to define the data for the test cases.
    • Requires only a single generic test function which takes the test case data and executes the test of the functionality.
    • Can decorate a entirely empty unittest.TestCase class - no boiler plate coded needed within the class.
    • Using the default settings, ensures a unique and predictable set of test method names, and useful documentation strings for each test case.
    • The automatically generated test methods work correctly with unittest module module default test detection, loaders, execution and reporting functionality.
    • Supports the use of the normal commandline usage of the unittest module, including execution of specific test cases.
  • Behind the scenes
    • Automatically generates a test method on a unittest.TestCase, one for each entry the test data list/Iterable.
    • By generating unique documentation strings and test names, ensures useful test result reporting from the unittest module.
    • By generating multiple test methods, ensures test separation so that testing continues after a test failure.
  • Also
    • Allows for customisation of the name and the documentation strings of the generated test method, using any of the data from the relevant test_case.
    • Provides additional decorators allowing the application of unittest test method decorators (^{tt2}$, ^{tt3}$ etc) to one or more of the automatically generated test cases. Can also apply your own arbitrary test method decorators to the generated test case methods.
    • Can combine Automatically generated test methods and explicitly provided test method on the same unittest.TestCase class.

请参阅Using the Framework以获取有关如何使用框架的完整详细信息,包括如何自定义框架,以及如何将decorators应用于生成的测试方法。

请参阅Why Use the Framework,以获得框架与使用unittest模块实现相同功能项(具有不同数据)的相同多个测试用例的其他传统方法的更详细比较。

安装

安装非常简单:

$ pip install repeated-test-framework

升级现有安装使用

$ pip install --upgrade repeated-test-framework

开始

下面的代码片段将演示框架执行少量测试用例的最简单用法 反对乘法运算-一个微不足道的例子,仍然是关键点的说明。

fromrepeatedtestframeworkimportGenerateTestMethodsdeftest_method_wrapper(index,a,b,result):deftest_method(self):"""The actual test method which gets replicated"""self.assertEqual(a*b,result)returntest_method_wrapper@GenerateTestMethods(test_name='test_multiplication',test_method=test_method_wrapper,test_input=[{'a':1,'b';2,'result':2},{'a':2,'b':2,'result':4},{'a':3,'b':2,'result':6},{'a':3,'b':4,'result':11}])classTestCases(unittest.TestCase):pass

尽管上面的示例很简单,但它确实说明了前面提到的框架的关键特性。

  • The data to be used is provided as a list of dictionaries; the ^{tt4}$ attribute on the GenerateTestMethods decorator.
  • A ^{tt5}$ attribute is provided - which is a human readable string which is included verbatim into the test method name - as such it can only include alphabetic, numeric and underscore (_) characters.
  • Regardless of the number of test data items the decorator only needs a a single test execution method (^{tt6}$ in the example) is required. The Framework replicates this method into the multiple test methods on the decorated class.
  • The framework does require the test function to be wrapped in method which accepts the attributes from the ^{tt4}$ iterator - in the example below this wrapping function is ^{tt8}$. As shown in the example, the wrapper function it does not need to do anything at all other than wrap the test function, and accept the test data as a set of arguments which can then be used by the wrapped test function.
  • The unittest.TestCase class being decorated by the Framework can be entirely empty (as in the example), or it can include set Up and clear down methods as required by the test cases, or it could even include one or more hand-written test case methods (so long as the method names do not clash).

疑难解答和错误

注意

我们会尽一切努力确保这段代码不会出现错误。 如果您确实发现错误-请将问题报告到:

许可证

本软件包含在Apache Software License 2.0许可证的条款中。

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

推荐PyPI第三方库


热门话题
JavaPax考试:从非标准Maven存储库解析Karaf特性存储库(XML文件)   java Spring启动Bean创建异常   java中将ArrayList转换为数组的方法   Android Studio的java Unity插件。   java在CheckStyle中从方法计数中排除getter和setter   HibernateJava。sql。SQLSyntaxErrorException:表/视图“序列”不存在   与命令行程序Java vs C通信   java WebView膨胀异常   java在O(n)java8流中寻找两个列表的交集   java使用Gradle运行单元测试时,最大堆大小在哪里设置?   ssl加载java应用程序(CXF)内的jks文件   CI:Jenkins Git:Simple Java项目:希望在特定时间在脚本上发送消息   java根据位置更改数字   java按数值排序字符串数组   macos java版本“1.6.0_65”是否与java 6模棱两可?   Cassandra中的java时间戳