【问题标题】:Geb Spock - Repeating the Entire Test SuiteGeb Spock - 重复整个测试套件
【发布时间】:2017-09-19 13:03:06
【问题描述】:

结合 Geb 和 Spock,有没有办法迭代整个测试套件?

例如,考虑一个测试套件类 - MyExampleTestSpec,其中包含两个规范。

Class MyExampleTestSpec extends GebSpec {

  def "testSpec1"(){
    when:
    then:
  }

  def "testSpec2"(){
   given:
   when:
   then:

   where:
 }
}

可以使用“where”子句重新迭代单个规范。但是重新迭代整个套件的选项是什么?

请告诉我。 提前致谢!

【问题讨论】:

  • 如果你的意思是 re-iterate 的数据驱动规范,那么我可以告诉你 spock 不提供这样的功能。

标签: spock geb


【解决方案1】:

所以这真的取决于你在测试什么。默认情况下,无法在类级别上执行 where。您可以制作注释以从源中提取并替换值。

我所做的是进行了更通用的测试。请注意,参数可以插入到 BDD 方法 cmets 中。您可以将这些设置为自定义参数。唯一的问题是您每次都需要拥有相同数量的元素。

@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()]
            ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 2012-06-10
    • 1970-01-01
    相关资源
    最近更新 更多