首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Fancordion验证返回HTTP404的RESTful服务?

如何使用Fancordion验证返回HTTP404的RESTful服务?
EN

Stack Overflow用户
提问于 2015-02-12 12:17:46
回答 1查看 184关注 0票数 1

我正在用RESTful编程语言编写范汤姆 API。我使用范考迪翁编写验收测试,并具有以下场景:

Country.fandoc

代码语言:javascript
复制
Country by Code
###############
Passing a country code as a parameter to the Country RESTful service must return the corresponding country
Example
-------
- Given the URL to get the details of Andorra [/country/AD]`set:countryUrl`
- When I send a HTTP GET request to it
- Then I expect the name to be [Andorra]`verifyEq:countryByCode.name`.

CountryFixture.fan

代码语言:javascript
复制
using afBedSheet
using afBounce
using afButter
using afFancordion
using util

@Fixture { specification=`specs/Country.fandoc` }
class CountryFixture : BaseFixture {

  Str? countryUrl

  Country countryByCode() {
    server := BedServer(AppModule#).startup
    client := server.makeClient
    response := client.sendRequest(ButterRequest(`$countryUrl`)).asStr
    Str:Obj? json := JsonInStream(response.in).readJson
    country := Country.fromJson(json)
    return country
  }
}

这个效果很好。现在,我要验证,当向请求传递无效的国家代码时,RESTful服务返回一个HTTP404错误,正如我使用浏览器实现和验证的那样。但是,我还没有在Fancordion文档中找到如何验证是否返回了HTTP 404错误。相反,我得到的是一个固定的失败。

代码语言:javascript
复制
***
*** 1 Fixtures FAILED [6 Fixtures]
***

我对此场景的验收测试(附加于Country.fandoc):

代码语言:javascript
复制
Wrong Country Code
##################
Passing a wrong country code as a parameter to the Country RESTful service must cause it to return a HTTP 404 error

Example
-------
- Given the URL to get the details of country that does not exist [/country/XX]`set:countryUrl`
- When I send a HTTP GET request to it
- Then I expect a HTTP 404 error when I try `verifyEq:countryByCode`

请问我怎样才能赶上404呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-17 23:07:23

如果您正在寻找类似于verifyErr(Type errType)方法的东西,那么Fancordion没有。这是因为这些方法与实现紧密结合在一起,这并不适合Fancordion测试的风格。

相反,使用以下方法禁用黄油引发的404错误:

代码语言:javascript
复制
client.errOn4xx.enabled = false

并让Fancordion固定装置设置响应。

代码语言:javascript
复制
Uri? url
ButterResponse? response

Void httpGet() {
  client := BedServer(AppModule#).startup.makeClient
  client.errOn4xx.enabled = false
  this.response = client.get(url)
}

然后让Fancordion规范验证状态代码:

代码语言:javascript
复制
Example
-------
- Given the URL to Unknown is [/country/XX]`set:url`
- When I send a [HTTP GET request]`exe:httpGet`
- Then I expect the returned status code to be [404]`eq:response.statusCode`.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28477281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档