如何使用Fancordion验证返回HTTP 404的RESTful服务?
我正在用编程语言编写一个RESTful API。我正在使用编写验收测试,并具有以下场景: Country.fandoc如何使用Fancordion验证返回HTTP 404的RESTful服务?,rest,fantom,afbedsheet,Rest,Fantom,Afbedsheet,我正在用编程语言编写一个RESTful API。我正在使用编写验收测试,并具有以下场景: Country.fandoc 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
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`.
范先生
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服务返回HTTP 404错误,正如我使用浏览器实现和验证的那样。然而,我还没有在Fancordion文档中找到如何验证HTTP 404错误是否返回的方法。相反,我得到的是一个固定装置故障
***
*** 1 Fixtures FAILED [6 Fixtures]
***
我对这个场景的验收测试是(附加到Country.fandoc):
请问我怎样才能找到404?如果您正在寻找类似于
verifyErr(Type errType)
方法的方法,Fancordion没有。这是因为这些方法与实现紧密耦合,而实现并不真正适合Fancordion测试的风格
相反,请使用以下命令禁用由引发的404错误:
并让Fancordion装置设置响应
Uri? url
ButterResponse? response
Void httpGet() {
client := BedServer(AppModule#).startup.makeClient
client.errOn4xx.enabled = false
this.response = client.get(url)
}
然后让Fancordion规范验证状态代码:
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`.
Uri? url
ButterResponse? response
Void httpGet() {
client := BedServer(AppModule#).startup.makeClient
client.errOn4xx.enabled = false
this.response = client.get(url)
}
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`.