是否可以配置黄瓜运行相同的测试与不同的弹簧配置文件? [英] Is it possible to configure cucumber to run the same test with different spring profiles?

查看:312
本文介绍了是否可以配置黄瓜运行相同的测试与不同的弹簧配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我在使用不同的技术运行试用。我有一组实现每种技术的接口,我使用弹簧配置文件来决定运行哪种技术。每个技术都有自己的Spring java配置注释与他们活动的配置文件。



我运行我的黄瓜测试定义哪个配置文件是活动的,但这迫使我手动更改字符串每次我想测试一个不同的配置文件,使其不可能为所有的运行自动化测试。在黄瓜中还有提供一组配置文件,所以测试每次运行一次?



谢谢!




  1. 标准 - 使用少数由Cucumber runners运行的测试类

  2. 编写支持多种配置的自定义Cucumber jUnit转换器(或准备好的转换器)。

strong>在第一种情况下,它将如下所示。缺点是,你必须为每个跑步者定义不同的报告,并且每个配置都有几乎相同的Cucumber跑步者。





以下是类的样子:



CucumberRunner1.java

  @RunWith(Cucumber.class)
@CucumberOptions(glue = {com.abc.def ,com.abc.common},
features = {classpath:com / abc / def /,
classpath:com / abc / common.feature},
format = {json:target / cucumber / cucumber-report-1.json},
tags = {〜@ ignore},
monochrome = true)
public class CucumberRunner1 {
}

StepAndConfig1.java

  @ContextConfiguration(locations = {classpath:/com/abc/def/configuration1.xml})
public class StepsAndConfig1 {
@Then(^ some useful step $)
public void someStep(){
int a = 0;
}
}

CucumberRunner2.java

  @RunWith(Cucumber.class)
@CucumberOptions(glue = {com.abc .ghi,com.abc.common},
features = {classpath:com / abc / ghi /,
classpath:com / abc / common.feature},
format = {json:target / cucumber / cucumber-report-2.json},
tags = {〜@ ignore},
monochrome = true)
public class CucumberRunner2 {
}

OnlyConfig2.java

  @ContextConfiguration(classes = JavaConfig2.class)
public class OnlyConfig2 {
@Before
public void justForCucumberToPickupThisClass(){}
}

是使用支持多种配置的自定义黄瓜转轮。您可以自行编写或准备一份,例如我的 CucumberJar.java 和项目根 cucumber-junit
在这种情况下,Cucumber转轮将看起来像这样:



CucumberJarRunner.java

  @RunWith(CucumberJar.class)
@CucumberOptions(glue = {com.abc.common},
= {〜@ ignore},
plugin = {json:target / cucumber / cucumber-report-common.json})
@CucumberGroupsOptions({
@CucumberOptions {com.abc.def},
features = {classpath:com / abc / def /,
classpath:com / abc / common.feature}

@CucumberOptions(glue = {com.abc.ghi},
features = {classpath:com / abc / ghi /,
classpath:com / abc / common。 feature}

})
public class CucumberJarRunner {
}


I have an application where I'm running a trial with different technologies. I have a set of interfaces implemented with each technology and I use spring profiles to decide which technology to run. Each of the technologies has its own Spring java config annotated with the profile they are active for.

I run my cucumber tests defining which profile is the active one but this forces me to manually change the string every time I want to test a different profile, making it impossible to run automated tests for all of them. Is there anyway in cucumber to provide a set of profiles so tests are run once for each of them?

Thanks!

解决方案

You have two possibilities

  1. Standard - use few test classes ran by Cucumber runners
  2. Write custom Cucumber jUnit runner (or take ready one) that supports multiple configurations.

In the first case, it will look like below. The disadvantage is that you have to define different reports for each runner and have almost identical Cucumber runners for each config.

Here's how classes can look like:

CucumberRunner1.java

@RunWith(Cucumber.class)
@CucumberOptions(glue = {"com.abc.def", "com.abc.common"},
        features = {"classpath:com/abc/def/",
                "classpath:com/abc/common.feature"},
        format = {"json:target/cucumber/cucumber-report-1.json"},
        tags = {"~@ignore"},
        monochrome = true)
public class CucumberRunner1 {
}

StepAndConfig1.java

@ContextConfiguration(locations = {"classpath:/com/abc/def/configuration1.xml"})
public class StepsAndConfig1 {
    @Then("^some useful step$")
    public void someStep(){
        int a = 0;
    }
}

CucumberRunner2.java

@RunWith(Cucumber.class)
@CucumberOptions(glue = {"com.abc.ghi", "com.abc.common"},
        features = {"classpath:com/abc/ghi/",
                "classpath:com/abc/common.feature"},
        format = {"json:target/cucumber/cucumber-report-2.json"},
        tags = {"~@ignore"},
        monochrome = true)
public class CucumberRunner2 {
}

OnlyConfig2.java

@ContextConfiguration(classes = JavaConfig2.class)
public class OnlyConfig2 {
    @Before
    public void justForCucumberToPickupThisClass(){}
}

The second approach is to use custom cucumber runner that supports multiple configurations. You can either write it by yourself or take ready one, for example, mine - CucumberJar.java and root of project cucumber-junit. In this case Cucumber runner will looks like this:

CucumberJarRunner.java

@RunWith(CucumberJar.class)
@CucumberOptions(glue = {"com.abc.common"},
        tags = {"~@ignore"},
        plugin = {"json:target/cucumber/cucumber-report-common.json"})
@CucumberGroupsOptions({
        @CucumberOptions(glue = {"com.abc.def"},
                features = {"classpath:com/abc/def/",
                        "classpath:com/abc/common.feature"}
        ),
        @CucumberOptions(glue = {"com.abc.ghi"},
                features = {"classpath:com/abc/ghi/",
                        "classpath:com/abc/common.feature"}
        )
})
public class CucumberJarRunner {
}

这篇关于是否可以配置黄瓜运行相同的测试与不同的弹簧配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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