最开始看到这个词感受怪怪的,词典解释是江湖骗子、卖假药的意思,感受很奇妙,为啥子取这个名字。
官网图片以下,确实有一瓶药。git
Mountebank究竟是什么?
从我使用的理解,就是给开发者提供假的api,替换掉被真实依赖的api,这在测试场景中常常用到。github
如何使用,能够单独使用,按照官网教程就好,也能够结合docker使用。
后续我会把单独使用的demo以及结合docker使用的demo 上传至github 供你们参考,欢迎提意见。
详细的步骤请参考git里面的commit信息。
第一个get api 效果如图docker
纯数据代码只有下面一部分shell
{ "port": 4545, "protocol": "http", "stubs": [{ "responses": [{ "is": { "statusCode": 200, "headers": { "Content-Type": "application/json" }, "body": ["Australia", "Brazil", "Canada", "Chile", "China", "Ecuador", "Germany", "India", "Italy", "Singapore", "South Africa", "Spain", "Turkey", "UK", "US Central", "US East", "US West"] } }], "predicates": [{ "equals": { "path": "/country", "method": "GET" } }] }, { "responses": [{ "is": { "statusCode": 400, "body": { "code": "bad-request", "message": "Bad Request" } } }] }] }
而须要把数据run起来 脚本部分只要shell就好json
#!/bin/sh set -e RUN_RESULT=$(docker ps | grep hasanozgan/mountebank | wc -l) MOUNTEBANK_URI=http://localhost:2525 BANK_IS_OPEN=1 if [ "$RUN_RESULT" -eq 0 ]; then docker run -p 2525:2525 -p 4545:4545 -d hasanozgan/mountebank fi curl $MOUNTEBANK_URI/imposters || BANK_IS_OPEN=0 if [ $BANK_IS_OPEN -eq 1 ]; then break fi curl -X DELETE $MOUNTEBANK_URI/imposters/4545 curl -X POST -H 'Content-Type: application/json' -d @stubs.json $MOUNTEBANK_URI/imposters
为何选用mountebank,
一个缘由是由于以前没用过,只是听到国内一些讲测试的文章有说过,看完并无get太多的点,还不如动手玩一下;
另外更重要的缘由是恰好一个codebase有现成的,有项目契机作事情很lucky。api
抛开这些自身兴趣和巧合,我推荐开发者选用mountebank的缘由大概会有如下几个app
轻量级 无平台依赖curl
多语言 多协议支持ide
免费post
有UI交互有趣
更多的自诩部分参见Why mountebank?
Trivial to get started
mountebank is easy to install, without any platform dependencies. mountebank aims for fun and comprehensive documentation with lots of examples, and a nice UI that lets you explore the API interactively.A platform, not just a tool
mountebank aims to be fully cross-platform, with native language bindings. Servers are extensible through scripting when the out of the box functionality isn't enough.Powerful
mountebank is the only open source service virtualization tool that is non-modal and multi-protocol. Commercial solutions exist, but their licensed platforms make it hard to move the tests closer to development and may even require a specialized IDE. mountebank provides service virtualization free of charge without any platform constraints
其实目前我也刚使用不久,也不知道啥太大的缺点,而关于何时使用呢?当有须要mock假的依赖的api的时候,就可使用,感受和没说同样。只是目前国内使用的很少,想一想先积累点使用经验也是好的,说不定又激发新的灵感。