有一个api蓝图dredd测试问题让我困扰了一段时间。
我可以成功测试json格式的测试,但对于文本格式,它总是失败。
The fail message -> fail: body: Real and expected data does not match.
但我检查预期和真实的身体是一样的。
任何人都可以帮助我或给我一些建议吗?我非常感激。
以下是我的代码:
### Get counting camera [GET]
+ Response 200 (text/plain)
+ Body
vadp_module_number='3'
vadp_module_order='1,2,0'
以下是dredd测试结果:
fail: body: Real and expected data does not match.
expected:
headers:
Content-Type: text/plain
body:
vadp_module_number='3'
vadp_module_order='1,2,0'
statusCode: 200
actual:
statusCode: 200
headers:
date: Thu, 14 Jun 2018 14:09:39 GMT
server: Boa/0.94.14rc21
accept-ranges: bytes
connection: close
content-type: text/plain
cache-control: no-cache
pragma: no-cache
content-length: 4856
body:
vadp_module_number='3'
vadp_module_order='1,2,0'
答案 0 :(得分:0)
似乎您的身体没有正确缩进。
camera.md
FORMAT: 1A
HOST: http://127.0.0.1:5000
# Camera
The camera is a simple API allowing consumers to manage your security cameras.
## Camera [/camera]
### Get counting camera [GET]
+ Response 200 (text/plain; charset=utf-8)
+ Body
vadp_module_number='3'
vadp_module_order='1,2,0'
我使用Drakov模拟服务器和Dredd对其进行了测试,并且运行良好。
drakov -f ./camera.md --public --watch --discover
dreed.yml(片段)
...
hooks-worker-handler-port: 61321
config: doc/examples/dredd.yml
blueprint: doc/examples/camera.md
endpoint: 'http://localhost:5000'
并运行:
dredd --config ./dredd.yml
或者也运行dredd with docker。
结果
info: Configuration './dredd.yml' found, ignoring other arguments.
2018-06-25T17:30:23.883Z - warn: Parser warning in file 'camera.md': message-body asset is expected to be a pre-formatted code block, every of its line indented by exactly 12 spaces or 3 tabs on lines 17-18
2018-06-25T17:30:23.884Z - info: Beginning Dredd testing...
2018-06-25T17:30:23.920Z - pass: GET (200) /camera duration: 34ms
2018-06-25T17:30:23.920Z - complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
2018-06-25T17:30:23.921Z - complete: Tests took 36ms
答案 1 :(得分:0)
与API蓝图结合使用时,Dredd可能会在带有文本/纯文本主体的尾随换行符上失败。参见apiaryio/dredd#67。
有关变通办法,请参阅Dredd文档中的Remove trailing newline character in expected plain text bodies部分:
setEnabled is not a function