与Geb和Spock结合使用,有没有办法迭代整个测试套件?
举个例子,考虑一个测试套件类 - MyExampleTestSpec,里面有两个规格。
Class MyExampleTestSpec extends GebSpec {
def "testSpec1"(){
when:
then:
}
def "testSpec2"(){
given:
when:
then:
where:
}
}
可以使用“where”子句重新编写单个Spec。但重新整合整个套件的选择是什么?
请告诉我。 提前谢谢!
答案 0 :(得分:0)
所以这真的取决于你在测试什么。默认情况下,无法在类级别上执行任何操作。你可以制作一个注释来从源中提取并对值进行替换。
我所做的事情是进行更通用的测试。请注意,参数可以插入到BDD方法注释中。你可以将这些作为自定义参数。唯一的问题是你每次都需要拥有相同数量的元素。
@Unroll
def "Failed request to obtain Oath Token by #failure"(){
given: "a user is attempting to use the 'Obtain OAuth Token' endpoint"
when: "the Content-Type is set to #content_type"
request.setContentType(content_type)
and: "the Accept type is set to #accept"
request.addHeader("Accept", accept)
and: "the user sets the client_id as #clientId"
and: "the user set the client_secret as #clientSecret"
and: "the grant_type is set as #grantType"
and: "the request type is #requestType"
request.setPostBody(ApiRequestBody.oAuthBody(client_id:clientId,client_secret:clientSecret,grant_type:grantType))
response = request.postExecute()
then: "an appropriate status code (#status) is returned"
response.status == status
and: "the error response is '#error_message'"
response.data.errors[0].message == error_message
and: "the error code is #error_code"
response.data.errors[0].code == error_code
and: "the response type is #response_type"
response.contentType == response_type
where:
[failure, content_type, accept, clientId, clientSecret, grantType, requestType, status, error_message, error_code, response_type] <<
[
["wrong grant_type",ContentType.URLENC,ContentType.JSON,ID,SECRET,"${GRANT}_wrong","POST", ApiUtility.ERRORS.'113'.status, ApiUtility.ERRORS.'113'.message, ApiUtility.ERRORS.'113'.code, ContentType.JSON.toString()],
["wrong Client_Secret",ContentType.URLENC,ContentType.JSON,ID,"${SECRET}_Wrong",GRANT,"POST", ApiUtility.ERRORS.'112'.status, ApiUtility.ERRORS.'112'.message, ApiUtility.ERRORS.'112'.code, ContentType.JSON.toString()],
["wrong Client_ID",ContentType.URLENC,ContentType.JSON,"${ID}_Wrong",SECRET,GRANT,"POST", ApiUtility.ERRORS.'112'.status, ApiUtility.ERRORS.'112'.message, ApiUtility.ERRORS.'112'.code, ContentType.JSON.toString()],
["mismatch of ID and Secret",ContentType.URLENC,ContentType.JSON,ID,otherToken,GRANT,"POST", ApiUtility.ERRORS.'112'.status, ApiUtility.ERRORS.'112'.message, ApiUtility.ERRORS.'112'.code, ContentType.JSON.toString()],
["an empty body",ContentType.URLENC,ContentType.JSON,"","","","POST", ApiUtility.ERRORS.'114'.status, "Missing or invalid parameters client_id,client_secret,grant_type", ApiUtility.ERRORS.'114'.code, ContentType.JSON.toString()],
["an empty grant_type",ContentType.URLENC,ContentType.JSON,ID,SECRET,"","POST", ApiUtility.ERRORS.'114'.status, "Missing or invalid parameters grant_type", ApiUtility.ERRORS.'114'.code, ContentType.JSON.toString()],
["an empty Client_Secret",ContentType.URLENC,ContentType.JSON,ID,"",GRANT,"POST", ApiUtility.ERRORS.'114'.status, "Missing or invalid parameters client_secret", ApiUtility.ERRORS.'114'.code, ContentType.JSON.toString()],
["an empty Client_ID",ContentType.URLENC,ContentType.JSON,"",SECRET,GRANT,"POST", ApiUtility.ERRORS.'114'.status, "Missing or invalid parameters client_id", ApiUtility.ERRORS.'114'.code, ContentType.JSON.toString()],
["wrong Content_Type",ContentType.JSON,ContentType.JSON,ID,SECRET,GRANT,"POST", ApiUtility.ERRORS.'114'.status, "Missing or invalid parameters client_id,client_secret,grant_type", ApiUtility.ERRORS.'114'.code, ContentType.JSON.toString()]
]
}