根据环境执行特定的Geb测试 [英] Executing Specific Geb Tests according to environement

查看:162
本文介绍了根据环境执行特定的Geb测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我在本地时,我需要执行一组特定的规格,而另一个规则当我运行pre-prod环境时设置Spec。
我目前的配置是同时执行我所有的规范,这是我想要避免的两个环境。



我有多个环境,已在我的GebConfig中配置:

  environments {
local {
baseUrl =http:// localhost :8090 / myApp / login / auth
}

pre-prod {
baseUrl =https:// preprod / myApp / login / auth
}


code $ <$ pre

解决方案

使用spock配置文件。

为这两种测试类型创建注释 - @Local @PreProd ,例如在Groovy中:

$ p $ import $ java.lang.annotation

@保留(RetentionPolicy.RUNTIME)
@Target([ElementType.TYPE,ElementType.METHOD])
@Inherited
public @interface本地{}



下一步是相应地注释您的规格,例如:

  @Local 
class SpecificationThatRunsLocally扩展GebSpec {...}

然后创建 SpockConfig.groovy 文件放在您的 GebConfig.groovy 文件旁边,其中包含以下内容:

  def gebEnv = System.getProperty(geb.env)
if(gebEnv){
switch(gebEnv){
case'local':
runner {include Local}
break
case'pre-prod':
runner {include PreProd}
打破
}
}

编辑:它看起来像Grails使用它自己的测试运行器,这意味着在运行Grails规范时不会考虑SpockConfig.groovy。如果您需要它在Grails下工作,那么您应该使用@ IgnoreIf / @要求内置Spock扩展注释。

首先创建一个Closure类,其中包含应该启用给定规范的逻辑。您可以直接将逻辑作为闭包参数添加到扩展注释中,但如果您想要注解很多规范,则可能会烦恼地复制那些代码。

  class Local extends Closure< Boolean> {
public Local(){super(null)}
布尔doCall(){
System.properties ['geb.env'] =='local'
}
}
$ b $ class PreProd extends Closure< Boolean> {
public PreProd(){super(null)}
布尔doCall(){
System.properties ['geb.env'] =='pre-prod'
}
}

然后注释您的规格:

  @Requires(Local)$ b $ class class SpecificationThatRunsLocally extends GebSpec {...} 

@Requires(PreProd)
class SpecificationThatRunsInPreProd扩展了GebSpec {...}


I have a set of Spec tests I am executing within a Grails Project.

I need to execute a certain set of Specs when I am on local, and another set of Spec when I run the pre-prod environment. My current config is executing all my specs at the same time for both environements, which is something I want to avoid.

I have multiple environments, that I have configured in my GebConfig:

environments {
    local {
        baseUrl = "http://localhost:8090/myApp/login/auth"
    }

    pre-prod {
        baseUrl = "https://preprod/myApp/login/auth"
    }

}

解决方案

You could use a spock config file.

Create annotations for the two types of tests - @Local and @PreProd, for example in Groovy:

import java.lang.annotation

@Retention(RetentionPolicy.RUNTIME)
@Target([ElementType.TYPE, ElementType.METHOD])
@Inherited
public @interface Local {}

Next step is to annotate your specs accordingly, for example:

@Local
class SpecificationThatRunsLocally extends GebSpec { ... }

Then create a SpockConfig.groovy file next to your GebConfig.groovy file with the following contents:

def gebEnv = System.getProperty("geb.env")
if (gebEnv) {
    switch(gebEnv) {
        case 'local':
            runner { include Local }
            break
        case 'pre-prod':
            runner { include PreProd }
            break 
    }
}

EDIT: It looks like Grails is using it's own test runner which means SpockConfig.groovy is not taken into account when running specifications from Grails. If you need it to work under Grails then the you should use @IgnoreIf/@Require built-in Spock extension annotations.

First create a Closure class with the logic for when a given spec should be enabled. You could put the logic directly as a closure argument to the extension annotations but it can get annoying to copy that bit of code all over the place if you want to annotate a lot of specs.

class Local extends Closure<Boolean> {
    public Local() { super(null) }
    Boolean doCall() {
        System.properties['geb.env'] == 'local'
    }
} 

class PreProd extends Closure<Boolean> {
    public PreProd() { super(null) }
    Boolean doCall() {
        System.properties['geb.env'] == 'pre-prod'
    }
}

And then annotate your specs:

@Requires(Local)
class SpecificationThatRunsLocally extends GebSpec { ... }

@Requires(PreProd)
class SpecificationThatRunsInPreProd extends GebSpec { ... }

这篇关于根据环境执行特定的Geb测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆