软件库API相似性测试的集成测试框架。
项目描述
双倍命令行工具
双倍命令行工具
是跨语言测试API相似性的集成测试框架。
保持相同的公共接口有什么价值?
本项目测试跨语言的库中的API一致性。
为什么这很重要?
- 对于开发者
- 减少跨语言实现更改时的沟通开销
- 迫使限制公共API的复杂性增长
- 对于用户
- 切换语言时无需重新学习API
- 切换语言时有更好的预期
有关更多信息,请点击下面的链接查看来自 satRdays Chicago 2019 会议的演讲
文档
有关最新文档,请参阅 https://doppel-cli.readthedocs.io/en/latest/。
入门
双倍命令行工具
可以像安装其他Python包一样从源安装。
python setup.py install
您还可以从PyPi安装,这是Python的官方包管理器。为了避免与该存储库中现有的 doppel
项目冲突,它作为 doppel-cli
发布。
pip install doppel-cli
R要求
要使用R包中的 doppel
,您将需要以下安装命令中显示的R包
Rscript -e "
install.packages(
c('argparse', 'futile.logger', 'jsonlite', 'R6')
, repos = 'http://cran.rstudio.com'
)
"
示例:测试R和Python实现之间的连续性
在这个例子中,我将展示如何使用 doppel
来测试同一API的R和Python实现之间的连续性。为此,我使用了 argparse
库。
注意:本例假设您已经在本地安装了 argparse
。
如果您没有运行一个或两个这些
Rscript -e "install.packages('argparse')"
pip install argparse
首先,您需要生成 doppel
使用来存储项目API信息的特殊文件。这些文件是通过 doppel-describe
工具创建的。
PACKAGE=argparse
# Create temporary directory to store output files
mkdir $(pwd)/test_data
# The R package
doppel-describe \
-p ${PACKAGE} \
--language R \
--data-dir $(pwd)/test_data
# The python package
doppel-describe \
-p ${PACKAGE} \
--language python \
--data-dir $(pwd)/test_data
太棒了!让我们来测试一下!可以使用 doppel-test
来比较多个包。
doppel-test \
--files $(pwd)/test_data/python_${PACKAGE}.json,$(pwd)/test_data/r_${PACKAGE}.json \
| tee out.log \
| cat
这将产生类似以下内容
Function Count
==============
+---------------------+----------------+
| argparse [python] | argparse [r] |
+=====================+================+
| 0 | 1 |
+---------------------+----------------+
Function Names
==============
+-----------------+---------------------+----------------+
| function_name | argparse [python] | argparse [r] |
+=================+=====================+================+
| ArgumentParser | no | yes |
+-----------------+---------------------+----------------+
Function Argument Names
=======================
No shared functions.
Class Count
===========
+---------------------+----------------+
| argparse [python] | argparse [r] |
+=====================+================+
| 9 | 0 |
+---------------------+----------------+
Class Names
===========
+-------------------------------+---------------------+----------------+
| class_name | argparse [python] | argparse [r] |
+===============================+=====================+================+
| MetavarTypeHelpFormatter | yes | no |
+-------------------------------+---------------------+----------------+
| ArgumentParser | yes | no |
+-------------------------------+---------------------+----------------+
| FileType | yes | no |
+-------------------------------+---------------------+----------------+
| HelpFormatter | yes | no |
+-------------------------------+---------------------+----------------+
| RawDescriptionHelpFormatter | yes | no |
+-------------------------------+---------------------+----------------+
| Action | yes | no |
+-------------------------------+---------------------+----------------+
| ArgumentDefaultsHelpFormatter | yes | no |
+-------------------------------+---------------------+----------------+
| Namespace | yes | no |
+-------------------------------+---------------------+----------------+
| RawTextHelpFormatter | yes | no |
+-------------------------------+---------------------+----------------+
Class Public Methods
====================
No shared classes.
Arguments in Class Public Methods
=================================
No shared classes.
Test Failures (12)
===================
1. Function 'ngettext()' is not exported by all packages
2. Function 'ArgumentParser()' is not exported by all packages
3. Packages have different counts of exported classes! argparse [python] (9), argparse [r] (0)
4. Class 'HelpFormatter()' is not exported by all packages
5. Class 'Namespace()' is not exported by all packages
6. Class 'RawDescriptionHelpFormatter()' is not exported by all packages
7. Class 'ArgumentParser()' is not exported by all packages
8. Class 'MetavarTypeHelpFormatter()' is not exported by all packages
9. Class 'Action()' is not exported by all packages
10. Class 'ArgumentDefaultsHelpFormatter()' is not exported by all packages
11. Class 'FileType()' is not exported by all packages
12. Class 'RawTextHelpFormatter()' is not exported by all packages
如上图所示,argparse
Python包有9个导出类,而R包一个都没有。
从 doppel
的角度来看,这被认为是测试失败。如果在终端中运行 echo $?
,应该会看到打印出 1
。返回非零退出码会通知CI工具(如 Travis)测试失败,这使得 doppel
对CI(更多内容将在未来的例子中介绍)非常有用。
您可能正在想“好吧,肯定不止是测试类和函数的数量,对吧?”。绝对是这样!请查看 项目问题 以了解我想要添加的功能的待办事项。欢迎PR!!!
要了解更多关于当前可配置的内容,可以运行
doppel-describe --help
和
doppel-test --help
贡献
错误报告、问题和功能请求应通过 问题页面 指导。
有关如何贡献的信息,请参阅 CONTRIBUTING.md。
项目详情
doppel-cli-0.3.1.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | ea363bba25f6f38f64e5a3a9d52d11e01483c1c532eb6bcd85eabbc89118cd1a |
|
MD5 | f77a961e80f0bc5f09ccd8060c2a916e |
|
BLAKE2b-256 | 6b7189ed8a5fb6b09fa04d2cbd9408bba910ca02ee70aca0832dc7039addaa70 |